Spaces:
Paused
Paused
P4.1: server-side H.264/AAC MP4 export (ffmpeg)
Browse files- Dockerfile +1 -0
- app.js +6 -6
- avatar.js +1 -1
- index.html +2 -2
- master.js +1 -1
- server/main.py +26 -0
- video.js +24 -11
- workspace.js +2 -2
Dockerfile
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
FROM python:3.12-slim
|
|
|
|
| 2 |
RUN useradd -m -u 1000 user
|
| 3 |
WORKDIR /home/user/app
|
| 4 |
COPY --chown=user server/requirements.txt server/requirements.txt
|
|
|
|
| 1 |
FROM python:3.12-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg && rm -rf /var/lib/apt/lists/*
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
WORKDIR /home/user/app
|
| 5 |
COPY --chown=user server/requirements.txt server/requirements.txt
|
app.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
import * as THREE from './vendor/three.module.min.js';
|
| 2 |
import { STUDIOS, stopLoops } from './widgets.js?v=50';
|
| 3 |
-
import './real.js?v=
|
| 4 |
-
import './avatar.js?v=
|
| 5 |
-
import './master.js?v=
|
| 6 |
-
import './video.js?v=
|
| 7 |
-
import './workspace.js?v=
|
| 8 |
-
import { icon } from './icons.js?v=
|
| 9 |
import { RoomEnvironment } from './vendor/addons/environments/RoomEnvironment.js';
|
| 10 |
import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
|
| 11 |
import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
|
|
|
|
| 1 |
import * as THREE from './vendor/three.module.min.js';
|
| 2 |
import { STUDIOS, stopLoops } from './widgets.js?v=50';
|
| 3 |
+
import './real.js?v=85';
|
| 4 |
+
import './avatar.js?v=85';
|
| 5 |
+
import './master.js?v=85';
|
| 6 |
+
import './video.js?v=85';
|
| 7 |
+
import './workspace.js?v=85';
|
| 8 |
+
import { icon } from './icons.js?v=85';
|
| 9 |
import { RoomEnvironment } from './vendor/addons/environments/RoomEnvironment.js';
|
| 10 |
import { EffectComposer } from './vendor/addons/postprocessing/EffectComposer.js';
|
| 11 |
import { RenderPass } from './vendor/addons/postprocessing/RenderPass.js';
|
avatar.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
|
| 2 |
// avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
|
| 3 |
import { STUDIOS, onStop } from './widgets.js?v=50';
|
| 4 |
-
import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=
|
| 5 |
|
| 6 |
const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
|
| 7 |
const slug = (n) => (n || 'avatar').toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '').slice(0, 40) || 'avatar';
|
|
|
|
| 1 |
// Avatar / Persona studio (DoD): persistent avatars as workspace asset type `avatar`
|
| 2 |
// avatars/<slug>/avatar.json + ref.webp + voice.wav · reused by Chat, Image (Kontext), agents.
|
| 3 |
import { STUDIOS, onStop } from './widgets.js?v=50';
|
| 4 |
+
import { run, result, MODULES, esc, hf, stTxt, url, badge, setS, keep, LS, FLUX, KONTEXT, TTS, CHAT, signedIn } from './real.js?v=85';
|
| 5 |
|
| 6 |
const LANGS = ['German', 'English', 'French', 'Spanish', 'Auto'];
|
| 7 |
const slug = (n) => (n || 'avatar').toLowerCase().normalize('NFKD').replace(/[^\w]+/g, '-').replace(/^-|-$/g, '').slice(0, 40) || 'avatar';
|
index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
| 8 |
<title>STUDIUS · DAS Studio — Einswarm</title>
|
| 9 |
<link rel="icon" href="assets/einswarm-mascot.webp">
|
| 10 |
<link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
-
<link rel="stylesheet" href="style.css?v=
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
@@ -49,6 +49,6 @@
|
|
| 49 |
|
| 50 |
<a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
|
| 51 |
<noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
|
| 52 |
-
<script type="module" src="app.js?v=
|
| 53 |
</body>
|
| 54 |
</html>
|
|
|
|
| 8 |
<title>STUDIUS · DAS Studio — Einswarm</title>
|
| 9 |
<link rel="icon" href="assets/einswarm-mascot.webp">
|
| 10 |
<link rel="preload" href="fonts/outfit-latin-wght.woff2" as="font" type="font/woff2" crossorigin>
|
| 11 |
+
<link rel="stylesheet" href="style.css?v=85">
|
| 12 |
</head>
|
| 13 |
<body>
|
| 14 |
<canvas id="gl"></canvas>
|
|
|
|
| 49 |
|
| 50 |
<a id="bmc" href="https://www.buymeacoffee.com/2btainment" target="_blank" rel="noopener noreferrer">Buy me a coffee</a>
|
| 51 |
<noscript><p style="color:#f2c94c;padding:2em">STUDIUS braucht JavaScript.</p></noscript>
|
| 52 |
+
<script type="module" src="app.js?v=85"></script>
|
| 53 |
</body>
|
| 54 |
</html>
|
master.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
|
| 2 |
// (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
|
| 3 |
import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
|
| 4 |
-
import { result, MODULES, esc, setS, keep } from './real.js?v=
|
| 5 |
|
| 6 |
/* ---------- BS.1770 loudness ---------- */
|
| 7 |
function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
|
|
|
| 1 |
// Mastering studio (DoD): client-side WebAudio chain EQ → compressor → limiter, loudness normalisation to target LUFS
|
| 2 |
// (ITU-R BS.1770-4 K-weighting + gating, measured offline), live meter, A/B, WAV/MP3 export, save to workspace.
|
| 3 |
import { STUDIOS, onStop, loop, cv } from './widgets.js?v=50';
|
| 4 |
+
import { result, MODULES, esc, setS, keep } from './real.js?v=85';
|
| 5 |
|
| 6 |
/* ---------- BS.1770 loudness ---------- */
|
| 7 |
function biquad(x, b0, b1, b2, a0, a1, a2) { const y = new Float32Array(x.length); b0 /= a0; b1 /= a0; b2 /= a0; a1 /= a0; a2 /= a0; let x1 = 0, x2 = 0, y1 = 0, y2 = 0;
|
server/main.py
CHANGED
|
@@ -285,6 +285,32 @@ def ws_pin(req: Request, bucket: str = Form(...), path: str = Form(...), studio:
|
|
| 285 |
api.batch_bucket_files(bucket, add=[(json.dumps(e, indent=1).encode(), mpath(p))]); return {"path": p, "pins": e["pins"]}
|
| 286 |
except Exception as e: herr(e)
|
| 287 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 288 |
@app.get("/api/quota")
|
| 289 |
async def quota(req: Request):
|
| 290 |
"""User's own ZeroGPU quota (GPU-seconds) from the Hub. Token stays server-side."""
|
|
|
|
| 285 |
api.batch_bucket_files(bucket, add=[(json.dumps(e, indent=1).encode(), mpath(p))]); return {"path": p, "pins": e["pins"]}
|
| 286 |
except Exception as e: herr(e)
|
| 287 |
|
| 288 |
+
@app.post("/api/transcode")
|
| 289 |
+
async def transcode(req: Request, file: UploadFile = File(...), name: str = Form("video"), bucket: str = Form(""), path: str = Form(""), studio: str = Form("videoedit"), prompt: str = Form("")):
|
| 290 |
+
"""WebM/any video -> H.264 (High, yuv420p) + AAC 48k MP4 with faststart (iPhone/Instagram/TikTok-safe).
|
| 291 |
+
Returns a tmp URL; optionally saves straight into the workspace bucket."""
|
| 292 |
+
import asyncio, shutil, subprocess
|
| 293 |
+
from .infer import tmp_put
|
| 294 |
+
s = need(req)
|
| 295 |
+
if not shutil.which("ffmpeg"): raise HTTPException(503, "ffmpeg not installed")
|
| 296 |
+
data = await file.read(MAX_UP + 1)
|
| 297 |
+
if len(data) > MAX_UP: raise HTTPException(413, "max 200 MB")
|
| 298 |
+
d = tempfile.mkdtemp(); src = f"{d}/in.bin"; stem = re.sub(r"[^\w.-]+", "-", Path(name).stem)[:80] or "video"; out = f"{d}/{stem}.mp4"
|
| 299 |
+
Path(src).write_bytes(data)
|
| 300 |
+
cmd = ["ffmpeg", "-hide_banner", "-loglevel", "error", "-y", "-i", src, "-map", "0:v:0", "-map", "0:a:0?",
|
| 301 |
+
"-vf", "scale=trunc(iw/2)*2:trunc(ih/2)*2:out_range=tv,fps=30,format=yuv420p", "-pix_fmt", "yuv420p", "-color_range", "tv", "-c:v", "libx264", "-profile:v", "high", "-level", "4.1", "-preset", "veryfast", "-crf", "20",
|
| 302 |
+
"-c:a", "aac", "-b:a", "160k", "-ar", "48000", "-ac", "2", "-movflags", "+faststart", out]
|
| 303 |
+
p = await asyncio.to_thread(subprocess.run, cmd, capture_output=True, text=True, timeout=600)
|
| 304 |
+
if p.returncode != 0 or not os.path.exists(out): shutil.rmtree(d, ignore_errors=True); raise HTTPException(422, "ffmpeg: " + (p.stderr or "failed")[-300:])
|
| 305 |
+
pr = await asyncio.to_thread(subprocess.run, ["ffprobe", "-v", "error", "-show_entries", "stream=codec_name,codec_type,width,height,profile,pix_fmt:format=duration", "-of", "json", out], capture_output=True, text=True)
|
| 306 |
+
info = json.loads(pr.stdout or "{}"); u = tmp_put(out); size = os.path.getsize(out); res = {"url": u, "size": size, "probe": info}
|
| 307 |
+
if bucket and path:
|
| 308 |
+
api = HfApi(token=s["token"])
|
| 309 |
+
try: res["saved"] = put(api, bid(bucket, s), Path(out).read_bytes(), safe(path), {"studio": studio, "prompt": prompt[:500], "source": "transcode:h264", "mime": "video/mp4"})
|
| 310 |
+
except Exception as e: res["save_error"] = str(e)[:200]
|
| 311 |
+
shutil.rmtree(d, ignore_errors=True)
|
| 312 |
+
return res
|
| 313 |
+
|
| 314 |
@app.get("/api/quota")
|
| 315 |
async def quota(req: Request):
|
| 316 |
"""User's own ZeroGPU quota (GPU-seconds) from the Hub. Token stays server-side."""
|
video.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
// STUDIUS P3.4: Video Gen (LTX-Video, text→video + image→video), Video Edit (trim, soundtrack, title, fades → MP4/WebM export)
|
| 2 |
// and Stems (Demucs split → synced mixer with gain/mute/solo → WAV mixdown). All results go on the asset bus (save / send).
|
| 3 |
-
import { run, result, MODULES, esc, hf, stTxt, url, badge, timer, setS, S, keep } from './real.js?v=
|
| 4 |
-
import { toWav } from './master.js?v=
|
| 5 |
import { onStop } from './widgets.js?v=50';
|
| 6 |
|
| 7 |
export const LTX = 'Lightricks/ltx-video-distilled';
|
|
@@ -39,8 +39,15 @@ export async function genVideo({ prompt, image, seconds = 2, size = '704x512' },
|
|
| 39 |
s.accept = async (el, a) => { const b = a.blob || await toBlob(a.url); el.__setImage?.(new File([b], a.name || 'start.webp', { type: b.type || 'image/webp' })); return true; };
|
| 40 |
}
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
/* ---------- VIDEO EDIT: trim, soundtrack, title, fades → export ---------- */
|
| 43 |
-
const recMime = () => ['video/mp4;codecs=avc1.42E01E,mp4a.40.2', 'video/
|
| 44 |
export async function renderEdit({ video, audio, a = 0, b = null, title = '', pos = 'bottom', fade = 0.5, music = 0.8, orig = 0.3 }, onP = () => {}) {
|
| 45 |
const v = document.createElement('video'); v.src = video; v.crossOrigin = 'anonymous'; v.playsInline = true; v.preload = 'auto';
|
| 46 |
await new Promise((ok, no) => { v.onloadedmetadata = ok; v.onerror = () => no(new Error('Video nicht ladbar')); });
|
|
@@ -51,17 +58,18 @@ export async function renderEdit({ video, audio, a = 0, b = null, title = '', po
|
|
| 51 |
let ab = null; if (audio) { const buf = await ac.decodeAudioData(await (await toBlob(audio)).arrayBuffer()); ab = ac.createBufferSource(); ab.buffer = buf; const mg = ac.createGain(); ab.connect(mg).connect(dst);
|
| 52 |
mg.gain.setValueAtTime(0, ac.currentTime); mg.gain.linearRampToValueAtTime(music, ac.currentTime + Math.max(.05, fade)); mg.gain.setValueAtTime(music, ac.currentTime + Math.max(.06, dur - fade)); mg.gain.linearRampToValueAtTime(0, ac.currentTime + dur); }
|
| 53 |
const stream = new MediaStream([...c.captureStream(30).getVideoTracks(), ...dst.stream.getAudioTracks()]);
|
| 54 |
-
const mime = recMime(), rec = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond:
|
| 55 |
v.currentTime = start; await new Promise(ok => v.onseeked = ok); v.muted = false; v.volume = 1;
|
| 56 |
const draw = () => { const t = v.currentTime - start; x.drawImage(v, 0, 0, W, H);
|
| 57 |
const al = Math.min(1, t / Math.max(.01, fade), (dur - t) / Math.max(.01, fade)); if (fade > 0 && al < 1) { x.fillStyle = `rgba(0,0,0,${1 - Math.max(0, al)})`; x.fillRect(0, 0, W, H); }
|
| 58 |
if (title) { const fs = Math.round(H / 12); x.font = `700 ${fs}px Outfit, sans-serif`; x.textAlign = 'center'; const y = pos === 'top' ? fs * 1.6 : pos === 'center' ? H / 2 : H - fs * 1.1;
|
| 59 |
x.lineWidth = fs / 6; x.strokeStyle = 'rgba(0,0,0,.75)'; x.strokeText(title, W / 2, y); x.fillStyle = '#f2c94c'; x.fillText(title, W / 2, y); }
|
| 60 |
onP(Math.min(1, t / dur)); };
|
|
|
|
| 61 |
const done = new Promise(ok => rec.onstop = ok); rec.start(250); ab?.start(); await v.play();
|
| 62 |
await new Promise(ok => { const tick = () => { draw(); if (v.currentTime >= end - 0.03 || v.ended) return ok(); requestAnimationFrame(tick); }; tick(); });
|
| 63 |
-
v.pause(); ab?.stop(); rec.stop(); await done; ac.close();
|
| 64 |
-
const type = (rec.mimeType || mime).split(';')[0], blob = new Blob(parts, { type }); return { blob, type, codec: rec.mimeType || mime, ext: type.includes('mp4') ? 'mp4' : 'webm', dur, w: W, h: H };
|
| 65 |
}
|
| 66 |
const EDIT = { v: null, vn: '', a: null, an: '' }, GEN = { img: null }, STM = { src: null, name: '' }; // survive studio re-open (hand-offs)
|
| 67 |
{ const s = S('videoedit'); s.real = 'LOKAL'; s.accepts = ['video', 'audio', 'image'];
|
|
@@ -87,10 +95,13 @@ const EDIT = { v: null, vn: '', a: null, an: '' }, GEN = { img: null }, STM = {
|
|
| 87 |
q('.pp').onclick = () => { const v = q('video'); if (!v) return; if (v.paused) { v.currentTime = T()[0]; v.play(); q('.pp').textContent = '⏸ Stop'; } else { v.pause(); q('.pp').textContent = '▶ Vorschau'; } };
|
| 88 |
q('.go').onclick = async () => { if (!vu) return; const go = q('.go'); go.disabled = true; q('video')?.pause(); const [a, b] = T();
|
| 89 |
try { const r = await renderEdit({ video: vu, audio: au, a, b, title: q('.tt').value.trim(), pos: q('.tp').value, fade: +q('.fd').value, music: q('.mv').value / 100, orig: q('.ov').value / 100 }, p => setS(el, `Rendere… ${Math.round(p * 100)} %`));
|
| 90 |
-
const u = URL.createObjectURL(r.blob); onStop(() => URL.revokeObjectURL(u)); const
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
| 94 |
} catch (e) { setS(el, '⚠ ' + e.message, true); window.__videoEdit = { err: e.message }; } finally { go.disabled = false; } };
|
| 95 |
el.__setVideo = setVideo; el.__setAudio = setAudio; if (EDIT.v) setVideo(EDIT.v, EDIT.vn); if (EDIT.a) setAudio(EDIT.a, EDIT.an);
|
| 96 |
};
|
|
@@ -151,7 +162,9 @@ MODULES.video = { id: 'video', name: 'Video', backend: LTX + ' + lokaler Schnitt
|
|
| 151 |
generate: { desc: 'Erzeugt ein 2–5 s Video aus einem Prompt (optional Startbild-url eines vorherigen Bildes)', params: { prompt: 'string', seconds: 'number' },
|
| 152 |
run: async ({ prompt, seconds = 2, image }, on = {}) => genVideo({ prompt, seconds, image: image ? await toBlob(image) : null }, { status: on.status }) },
|
| 153 |
score: { desc: 'Legt Musik (audio url) unter ein Video (video url), optional mit Titel, und exportiert es', params: { video: 'string', audio: 'string', title: 'string' },
|
| 154 |
-
run: async ({ video, audio, title = '' }) => { const r = await renderEdit({ video, audio, title }); const
|
|
|
|
|
|
|
| 155 |
MODULES.stems = { id: 'stems', name: 'Stems', backend: SEP, inputs: [{ name: 'source', type: 'audio-url' }], outputs: [{ kind: 'audio' }],
|
| 156 |
actions: { split: { desc: 'Trennt ein Audio (url) in Vocals + Instrumental; liefert das Instrumental', params: { source: 'string' },
|
| 157 |
run: async ({ source }, on = {}) => { const d = await run(SEP, '/inference', { audio: new File([await toBlob(source)], 'in.wav', { type: 'audio/wav' }) }, { onStatus: on.status, timeout: 240000 }); const u = d.map(url);
|
|
|
|
| 1 |
// STUDIUS P3.4: Video Gen (LTX-Video, text→video + image→video), Video Edit (trim, soundtrack, title, fades → MP4/WebM export)
|
| 2 |
// and Stems (Demucs split → synced mixer with gain/mute/solo → WAV mixdown). All results go on the asset bus (save / send).
|
| 3 |
+
import { run, result, MODULES, esc, hf, stTxt, url, badge, timer, setS, S, keep } from './real.js?v=85';
|
| 4 |
+
import { toWav } from './master.js?v=85';
|
| 5 |
import { onStop } from './widgets.js?v=50';
|
| 6 |
|
| 7 |
export const LTX = 'Lightricks/ltx-video-distilled';
|
|
|
|
| 39 |
s.accept = async (el, a) => { const b = a.blob || await toBlob(a.url); el.__setImage?.(new File([b], a.name || 'start.webp', { type: b.type || 'image/webp' })); return true; };
|
| 40 |
}
|
| 41 |
|
| 42 |
+
/* server-side H.264/AAC MP4 (faststart) – plays on iPhone/Instagram/TikTok */
|
| 43 |
+
export async function toH264(blob, name, onP = () => {}) {
|
| 44 |
+
if (!window.__ws?.me?.signedIn) return null; onP('MP4 (H.264) wird auf dem Server erzeugt…');
|
| 45 |
+
const f = new FormData(); f.append('file', blob, name); f.append('name', name);
|
| 46 |
+
const r = await fetch('/api/transcode', { method: 'POST', body: f, credentials: 'include' }); const j = await r.json().catch(() => ({}));
|
| 47 |
+
if (!r.ok) throw new Error(j.detail || 'Transcode HTTP ' + r.status); return j; }
|
| 48 |
+
|
| 49 |
/* ---------- VIDEO EDIT: trim, soundtrack, title, fades → export ---------- */
|
| 50 |
+
const recMime = () => (window.__ws?.me?.signedIn ? ['video/webm;codecs=vp8,opus', 'video/webm', 'video/webm;codecs=vp9,opus', 'video/mp4'] : ['video/mp4;codecs=avc1.42E01E,mp4a.40.2', 'video/webm;codecs=vp9,opus', 'video/webm;codecs=vp8,opus', 'video/webm', 'video/mp4']).find(m => window.MediaRecorder?.isTypeSupported?.(m)) || 'video/webm';
|
| 51 |
export async function renderEdit({ video, audio, a = 0, b = null, title = '', pos = 'bottom', fade = 0.5, music = 0.8, orig = 0.3 }, onP = () => {}) {
|
| 52 |
const v = document.createElement('video'); v.src = video; v.crossOrigin = 'anonymous'; v.playsInline = true; v.preload = 'auto';
|
| 53 |
await new Promise((ok, no) => { v.onloadedmetadata = ok; v.onerror = () => no(new Error('Video nicht ladbar')); });
|
|
|
|
| 58 |
let ab = null; if (audio) { const buf = await ac.decodeAudioData(await (await toBlob(audio)).arrayBuffer()); ab = ac.createBufferSource(); ab.buffer = buf; const mg = ac.createGain(); ab.connect(mg).connect(dst);
|
| 59 |
mg.gain.setValueAtTime(0, ac.currentTime); mg.gain.linearRampToValueAtTime(music, ac.currentTime + Math.max(.05, fade)); mg.gain.setValueAtTime(music, ac.currentTime + Math.max(.06, dur - fade)); mg.gain.linearRampToValueAtTime(0, ac.currentTime + dur); }
|
| 60 |
const stream = new MediaStream([...c.captureStream(30).getVideoTracks(), ...dst.stream.getAudioTracks()]);
|
| 61 |
+
const mime = recMime(), rec = new MediaRecorder(stream, { mimeType: mime, videoBitsPerSecond: 6e6 }), parts = []; rec.ondataavailable = (e) => e.data.size && parts.push(e.data);
|
| 62 |
v.currentTime = start; await new Promise(ok => v.onseeked = ok); v.muted = false; v.volume = 1;
|
| 63 |
const draw = () => { const t = v.currentTime - start; x.drawImage(v, 0, 0, W, H);
|
| 64 |
const al = Math.min(1, t / Math.max(.01, fade), (dur - t) / Math.max(.01, fade)); if (fade > 0 && al < 1) { x.fillStyle = `rgba(0,0,0,${1 - Math.max(0, al)})`; x.fillRect(0, 0, W, H); }
|
| 65 |
if (title) { const fs = Math.round(H / 12); x.font = `700 ${fs}px Outfit, sans-serif`; x.textAlign = 'center'; const y = pos === 'top' ? fs * 1.6 : pos === 'center' ? H / 2 : H - fs * 1.1;
|
| 66 |
x.lineWidth = fs / 6; x.strokeStyle = 'rgba(0,0,0,.75)'; x.strokeText(title, W / 2, y); x.fillStyle = '#f2c94c'; x.fillText(title, W / 2, y); }
|
| 67 |
onP(Math.min(1, t / dur)); };
|
| 68 |
+
const dbg = window.__recDbg = { mime, chunks: 0, err: null }; rec.onerror = (e) => dbg.err = String(e.error || e); const od = rec.ondataavailable; rec.ondataavailable = (e) => { dbg.chunks++; od(e); };
|
| 69 |
const done = new Promise(ok => rec.onstop = ok); rec.start(250); ab?.start(); await v.play();
|
| 70 |
await new Promise(ok => { const tick = () => { draw(); if (v.currentTime >= end - 0.03 || v.ended) return ok(); requestAnimationFrame(tick); }; tick(); });
|
| 71 |
+
draw(); await new Promise(r => setTimeout(r, 400)); v.pause(); ab?.stop(); dbg.frames = dbg.chunks; dbg.vt = v.currentTime; dbg.state = rec.state; if (rec.state !== 'inactive') { rec.requestData(); rec.stop(); } await done; ac.close();
|
| 72 |
+
const type = (rec.mimeType || mime).split(';')[0], blob = new Blob(parts, { type }); if (!blob.size) throw new Error('Aufnahme leer – Video-Codec im Browser nicht abspielbar?'); return { blob, type, codec: rec.mimeType || mime, ext: type.includes('mp4') ? 'mp4' : 'webm', dur, w: W, h: H };
|
| 73 |
}
|
| 74 |
const EDIT = { v: null, vn: '', a: null, an: '' }, GEN = { img: null }, STM = { src: null, name: '' }; // survive studio re-open (hand-offs)
|
| 75 |
{ const s = S('videoedit'); s.real = 'LOKAL'; s.accepts = ['video', 'audio', 'image'];
|
|
|
|
| 95 |
q('.pp').onclick = () => { const v = q('video'); if (!v) return; if (v.paused) { v.currentTime = T()[0]; v.play(); q('.pp').textContent = '⏸ Stop'; } else { v.pause(); q('.pp').textContent = '▶ Vorschau'; } };
|
| 96 |
q('.go').onclick = async () => { if (!vu) return; const go = q('.go'); go.disabled = true; q('video')?.pause(); const [a, b] = T();
|
| 97 |
try { const r = await renderEdit({ video: vu, audio: au, a, b, title: q('.tt').value.trim(), pos: q('.tp').value, fade: +q('.fd').value, music: q('.mv').value / 100, orig: q('.ov').value / 100 }, p => setS(el, `Rendere… ${Math.round(p * 100)} %`));
|
| 98 |
+
const u = URL.createObjectURL(r.blob); onStop(() => URL.revokeObjectURL(u)); const stem = `${vname}-edit-${Date.now()}`, raw = `${stem}.${r.ext === 'mp4' ? 'rec.mp4' : 'webm'}`;
|
| 99 |
+
let h = null, herr = ''; try { h = await toH264(r.blob, raw, m => setS(el, m)); } catch (e) { herr = e.message; }
|
| 100 |
+
const fu = h ? h.url : u, fname = h ? stem + '.mp4' : raw, vs = h?.probe?.streams?.find(x => x.codec_type === 'video');
|
| 101 |
+
q('.out').innerHTML = `<video controls playsinline src="${esc(fu)}"></video><div class="row">${h ? `<a class="btn" href="${esc(h.url)}" download="${esc(fname)}">⬇ MP4 H.264/AAC (${(h.size / 1e6).toFixed(1)} MB)</a>` : ''}<a class="btn alt" href="${u}" download="${esc(raw)}">⬇ Roh-${r.ext.toUpperCase()}</a></div>${h ? '<small class="mut">iPhone · Instagram · TikTok-tauglich (faststart)</small>' : `<small class="mut">${herr ? '⚠ H.264: ' + esc(herr) : 'Für H.264-MP4 anmelden'} – Roh-Export im Browser-Codec.</small>`}`;
|
| 102 |
+
window.__videoEdit = { size: h?.size || r.blob.size, type: h ? 'video/mp4' : r.type, codec: h ? `${vs?.codec_name} ${vs?.profile} ${vs?.pix_fmt}` : r.codec, h264: !!h, url: fu, dur: r.dur, music: !!au, title: q('.tt').value, err: herr || undefined };
|
| 103 |
+
result(q('.out'), h ? { kind: 'video', mime: 'video/mp4', url: h.url, name: fname, studio: 'videoedit', model: 'ffmpeg libx264+aac (server)', prompt: q('.tt').value } : { kind: 'video', mime: r.type, blob: r.blob, url: u, name: raw, studio: 'videoedit', prompt: q('.tt').value });
|
| 104 |
+
setS(el, `✔ Export ${h ? 'MP4 H.264' : r.ext.toUpperCase()} · ${r.dur.toFixed(1)} s${au ? ' · mit Musik' : ''}${q('.tt').value ? ' · mit Titel' : ''}`); badge(el, 'LOKAL');
|
| 105 |
} catch (e) { setS(el, '⚠ ' + e.message, true); window.__videoEdit = { err: e.message }; } finally { go.disabled = false; } };
|
| 106 |
el.__setVideo = setVideo; el.__setAudio = setAudio; if (EDIT.v) setVideo(EDIT.v, EDIT.vn); if (EDIT.a) setAudio(EDIT.a, EDIT.an);
|
| 107 |
};
|
|
|
|
| 162 |
generate: { desc: 'Erzeugt ein 2–5 s Video aus einem Prompt (optional Startbild-url eines vorherigen Bildes)', params: { prompt: 'string', seconds: 'number' },
|
| 163 |
run: async ({ prompt, seconds = 2, image }, on = {}) => genVideo({ prompt, seconds, image: image ? await toBlob(image) : null }, { status: on.status }) },
|
| 164 |
score: { desc: 'Legt Musik (audio url) unter ein Video (video url), optional mit Titel, und exportiert es', params: { video: 'string', audio: 'string', title: 'string' },
|
| 165 |
+
run: async ({ video, audio, title = '' }) => { const r = await renderEdit({ video, audio, title }); const n = `scored-${Date.now()}`; const h = await toH264(r.blob, n + '.webm').catch(() => null);
|
| 166 |
+
if (h) return { kind: 'video', mime: 'video/mp4', url: h.url, name: n + '.mp4', studio: 'videoedit', prompt: title, text: `Video mit Musik (${r.dur.toFixed(1)} s, H.264)` };
|
| 167 |
+
const u = URL.createObjectURL(r.blob); return { kind: 'video', mime: r.type, blob: r.blob, url: u, name: `${n}.${r.ext}`, studio: 'videoedit', prompt: title, text: `Video mit Musik (${r.dur.toFixed(1)} s)` }; } } } };
|
| 168 |
MODULES.stems = { id: 'stems', name: 'Stems', backend: SEP, inputs: [{ name: 'source', type: 'audio-url' }], outputs: [{ kind: 'audio' }],
|
| 169 |
actions: { split: { desc: 'Trennt ein Audio (url) in Vocals + Instrumental; liefert das Instrumental', params: { source: 'string' },
|
| 170 |
run: async ({ source }, on = {}) => { const d = await run(SEP, '/inference', { audio: new File([await toBlob(source)], 'in.wav', { type: 'audio/wav' }) }, { onStatus: on.status, timeout: 240000 }); const u = d.map(url);
|
workspace.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
// STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
|
| 2 |
-
import { MODULES, refreshQuota } from './real.js?v=
|
| 3 |
-
import { Avatars } from './avatar.js?v=
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 6 |
const ST = () => window.__studius.STUDIOS;
|
|
|
|
| 1 |
// STUDIUS empire backbone (frontend): HF sign-in, Workspace (user's HF Bucket), asset bus hand-off, bee agent dock.
|
| 2 |
+
import { MODULES, refreshQuota } from './real.js?v=85';
|
| 3 |
+
import { Avatars } from './avatar.js?v=85';
|
| 4 |
const $ = (s, r = document) => r.querySelector(s);
|
| 5 |
const esc = (t) => String(t ?? '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
| 6 |
const ST = () => window.__studius.STUDIOS;
|