SPB Git

Repository Public

VIDEO_PIPELINE.md 5.0 KB 50 lines markdown

1# Video pipeline23**Status: built; tested end to end with small synthetic videos generated by ffmpeg inside the tests. Never run on a real lecture recording.**45## Path of a video67```8browser ──4 MiB pieces + SHA-256 each──▶ /admin/api/uploads/…        uploads/<id>/000000…   (never served)9        complete: assemble, re-hash, magic bytes ─────────────────▶ masters/<sha256>.<ext>  (kept untouched, never served)10        job « transcode » in the SQLite queue ◀── worker process (scripts/worker.ts, PM2 « atlas-worker »)11            ffprobe validation → ffmpeg ladder → poster, thumbnails → work/job-<id>-<attempt>/12            atomic move ───────────────────────────────────────────▶ media/<session>/<capsule>/<encode>/13captions / transcript / chapters (validated) ─────────────────────▶ media/<session>/<capsule>/<name>.<hash>.<ext>14```1516## Layout of one capsule (what the player and the routes expect)1718```19ATLAS_DATA_DIR/media/<sessionId>/<capsuleId>/20  r<encode-id>/master.m3u8            one EXT-X-STREAM-INF per rendition: measured peak BANDWIDTH, RESOLUTION, CODECS read from the segments21  r<encode-id>/v<height>/index.m3u8, seg_00000.ts …   H.264 + AAC, 4 s segments, key frames forced every 4 s (aligned across renditions)22  r<encode-id>/fallback.mp4           progressive, faststart, best rendition ≤ 720 lines23  r<encode-id>/poster.jpg, thumbs/t_001.jpg …24  captions.<lang>.<hash>.vtt          normalised WebVTT, one per language25  transcript.<hash>.json              { lang, segments: [{ start, end, text }] }26  chapters.<hash>.json                [{ start, title }]27```2829It is the layout of `scripts/make-test-capsule.ts` with one addition: **every encode has its own directory and every sidecar file a name derived from its content**. Files are never rewritten in place, so a publication keeps naming exactly the bytes it was made with. `/media/[...path]` serves a file only if a *live publication* names it (`mediaAllowed`): a draft, a newer encode or a master has no public address at all.3031## Encoding3233- Ladder: `ATLAS_LADDER` (JSON) or the default 360p/800 kb/s, 720p/2800, 1080p/5000 (audio 96/128/160 kb/s AAC stereo 48 kHz). **Never upscaled**: only rungs at or below the source height; a source between two rungs (e.g. 480p) also gets a rung at its own height; a source below the first rung is delivered at its own size. Tested: 180p → [180], 360p → [360], 480p → [360, 480].34- `libx264`, preset `ATLAS_X264_PRESET` (default `medium`), CRF 21 capped by `-maxrate`, `main` profile below 720p and `high` from 720p, `yuv420p`. A silent source is encoded without an audio track (tested).35- Limits: `ATLAS_MAX_VIDEO_MIN` (240), `ATLAS_JOB_TIMEOUT_MIN` (240), `ATLAS_WORKER_CONCURRENCY` (1; max 4). ffmpeg/ffprobe run without a shell and are killed by PID on cancel or timeout.3637## Queue and worker3839Table `jobs`; states `queued → running → succeeded | failed | cancelled`. Three attempts with back-off (15 s, 1 min, 4 min); errors that retrying cannot fix (not a video, ffmpeg missing, master gone) fail at once with a French message shown on the capsule. The worker writes a heartbeat every loop; jobs of a worker that died are put back in the queue after 90 s; `SIGTERM` gives the running job back without consuming an attempt. Stale uploads are swept after two days.4041**ffmpeg is checked at run time** (`ffmpeg -version`, `-encoders` for libx264 and aac). If it is missing: the dashboard shows a red notice, `/api/health/details` and `pnpm studio health` report `ffmpeg.ok: false` with the reason, and encode jobs fail immediately with « ffmpeg est introuvable… » instead of hanging. The rest of the studio keeps working.4243## Storage and bandwidth — orders of magnitude, **not measured on real lectures**4445With the default ladder's caps (a ceiling; CRF usually lands lower for slides and talking heads): 360p + 720p + 1080p + MP4 fallback ≈ 0.8 + 2.8 + 5.0 + 2.8 Mb/s ≈ 11.4 Mb/s → **≈ 5 GB per hour of video at most**, plus the master (a 4K master is commonly 20–45 GB per hour). 24 sessions × ~1 h ≈ 120 GB of renditions at the ceiling, plus masters. A learner watching 720p uses ≈ 1.3 GB per hour at the cap. Measure the first real recording (`du -sh media/<session>/<capsule>`) and set `ATLAS_QUOTA_GB`; these figures are estimates from bitrates, nothing else. Old encodes are not deleted automatically (a publication may name them): **no garbage collector exists yet**.4647## Not built / not verified4849Waveforms; automatic poster choice (the poster is the frame at 3 s or 10 %); slide synchronisation; GPU or VideoToolbox encoding; purge of unreferenced encodes; real lecture-length sources; 4K sources; HDR, variable-frame-rate and rotated phone footage (rotation is read from metadata but untested); playback of the produced streams on a real iPhone/iPad (headless Chromium only for studio-produced media).50
Files main
Menu

Theme