Video Processing
NukeVideo uses FFmpeg to transcode uploaded videos into an adaptive ladder of renditions and shaka-packager to package them as CMAF (HLS and DASH over the same segments). The entire pipeline is queue-based and runs on distributed worker nodes.
Pipeline Overview
When a video is uploaded, the following jobs execute in order:
OnVideoUploaded — creates the video (PENDING) and its `original` stream
└── videos:dispatch — claims a worker slot (RUNNING)
└── PrepareVideoJob (orchestration queue)
├── download source once, give it a seek index if it lacks one,
│ mirror it to the chunk store (DOWNLOADING → RUNNING)
├── probe → outputs + streams
├── copy the audio + subtitle tracks out of the source to the chunk store
├── ExtractThumbnailJob ┐ in parallel with the encode
├── EncodeSidecarTracksJob ┘ (sidecar queue: one job per audio rendition + one for subtitles, never chunked)
├── per rendition: per-title CRF / bitrate probe / preflight
└── Bus::batch per hardware queue — one ProcessChunkJob per (window × rendition)
└── last batch's .then() (UPLOADING)
└── PackageVideoJob (packaging queue)
concat chunks → storyboard → shaka-packager → subtitles → s5cmd sync to S3
└── every output settles → video COMPLETED / FAILEDVideo Statuses
video.status tracks the pipeline phase. Output-level results are tracked on each output.
| Status | Description |
|---|---|
pending | Uploaded (or requeued by a retry), waiting to be dispatched |
downloading | Source file being fetched (from S3, or from the mirror on a retry), indexed if needed and mirrored |
running | Probing, planning and chunk encoding in progress |
uploading | Every chunk encoded; packaging and the upload to S3 in progress |
completed | All outputs have settled, at least one of them completed |
failed | No output could be produced |
Output Statuses
An output is one CMAF package, with its HLS and/or DASH manifests. Its status is what the playback mint reads to decide whether its manifests can be served.
| Status | Description |
|---|---|
pending | Waiting for the encode batch |
running | Chunks encoding in progress |
completed | Packaged and synced to S3, ready for playback |
failed | The run failed before this output was packaged |
Stream Types
Each video can have multiple streams:
| Type | Description |
|---|---|
original | The source file as uploaded |
video | Encoded video-only rendition |
audio | Encoded audio-only track |
subtitle | Text subtitle track, converted to WebVTT |
Streams are shared between outputs when their resolved parameters are identical, so two outputs with the same 720p rendition encode it once.
Processing Steps
1. Dispatch
The videos:dispatch scheduler (every five seconds) picks up pending videos by priority — high, then normal, then low, oldest first within each level — and dispatches a PrepareVideoJob for each one its hardware can take (see Dispatch and Hardware).
2. Download Original
The worker downloads the original from primary S3 exactly once and mirrors it to the LAN chunks store; every later job reads the mirror instead, and so does a retry while the mirror is still there (see Error Handling).
A Matroska or WebM source without a seek index (Cues) — common in files cut by streaming tools and in browser recordings — is rewritten with mkvmerge before it is mirrored. Every chunk opens the source at its own window, and without an index ffmpeg cannot jump there: it reads the file from its first byte, so a chunk near the end pulls the whole source over the network, and on a node far from the chunk store chunk after chunk runs out its timeout. The index is measured rather than looked up (a seek past the end that reads over half the file counts as missing), so a truncated one is caught too. This never fails the video: a source mkvmerge cannot rebuild within ten minutes, or whose rebuilt copy does not hold the same streams, is mirrored as it came. A mirror written before the check existed is checked, and replaced, on retry.
3. Probe & Create Streams
The source is probed with FFprobe (and mkvmerge, for Matroska language tags) to extract duration, resolution, codecs, audio and subtitle tracks. One output is created per entry of the template's query.outputs, with its streams:
- Video renditions: every variant is resolved against the source and never upscaled; variants that would produce the same size collapse into one. A variant without
gop_sizegets one derived from the source frame rate. - Audio: one track per source audio track and per distinct channel count of the template's channel ladder, never upmixed, and never at a higher bitrate than the source track's own.
- Subtitles: text tracks only (SRT, ASS/SSA, WebVTT, mov_text); bitmap and empty tracks are skipped.
Each video rendition is then settled against the source: target_vmaf steers the CRF per title, a bitrate probe measures what the quality mode costs, and a preflight encode proves the parameters work before anything fans out.
4. Encode Chunks
The video is divided into keyframe-aligned windows, sized per encoder so a chunk finishes inside the worker timeout. One ProcessChunkJob per (window × rendition) encodes and uploads its chunk to the chunk store, fanned out as one Bus::batch per hardware queue. A chunk already staged by an earlier attempt is reused, which is what makes a retry cheap — unless the retry plans that rendition differently (a deploy in between changed the window sizing or the encode parameters), in which case the rendition starts over rather than splice chunks of two plans together.
A chunk waits up to a minute for the node to have the memory its encode will take before starting ffmpeg. One the kernel's OOM killer stops is put back on the queue and encoded again, without counting as a failure, until it runs out of attempts.
Encoding progress is tracked per output in Redis and exposed via output.progress (0–100).
5. Audio & Subtitles
Audio and subtitles are encoded whole, never chunked: per-chunk audio concatenation corrupts gapless codecs such as Opus.
While the source is still on its local disk, the preparation copies the audio and subtitle tracks out of it, without re-encoding, into Matroska files on the chunk store: one per audio source track and one holding every subtitle. Together they are a few GB where the source can be tens, because the picture is most of a film's bytes, and each pass reads only the file with its own tracks.
Then one EncodeSidecarTracksJob runs per pass: one per audio rendition (a track's stereo and 5.1 are two jobs) and one for all the subtitles. A track's renditions are not encoded together: off one shared decode they wait on each other, and a TrueHD track's stereo and 5.1 took 571 s together on a loaded worker against 253 s and 238 s apart. Each reads its tracks copy rather than the source, has its own timeout and retries, and runs on whichever worker picks it up, so a film with many tracks encodes them side by side. The passes have their own sidecar queue, so a film with many tracks never holds the slots that prepare the next videos. When the copy cannot be made (Matroska cannot hold an MP4's mov_text subtitles as they are) or takes longer than 15 minutes, the passes read the source instead; a copy that never reaches the store costs time, never the video.
6. Extract Thumbnail
A thumbnail is extracted at 30% of the video duration, up to 1920 px wide (never upscaled), and uploaded to S3. A failure is logged and never fails the video.
7. Generate Storyboard
Sprite sheets are created for seek preview, during packaging, from a rendition already concatenated on the packaging worker's disk rather than from the source. That rendition is the smallest one at least 640 px wide (the widest, when none is), so nothing larger is decoded than the thumbnails show.
- Frames extracted at 10-second intervals, 640 px wide, the trick-play size for a full HD screen.
- Six columns per sheet, and as many rows as keep the sheet within 4096 px (ten for 16:9), the largest texture many TV browsers accept.
- A WebVTT file is generated with coordinates for each frame.
Like the thumbnail, a failure never fails the video: the storyboard is then simply absent.
8. Package & Settle
When the last encode batch finishes, the video moves to uploading and PackageVideoJob runs on one worker once every audio and subtitle track is staged. It concatenates each rendition's chunks with -c copy, packages every output with shaka-packager into shared CMAF segments, grafts the subtitles into the manifests, and s5cmd syncs everything to primary S3. Only then are the outputs marked completed, so a completed video is already servable.
The video is then marked completed if at least one output succeeded, or failed if none did. A completed video's copy of the source, chunks and staged tracks is removed from the chunk store at once, and its uploaded source is deleted from S3 — or archived under the video's prefix when the template sets keepOriginal.
Dispatch and Hardware
Chunk jobs are routed by the template's video codec: CPU codecs go to video-processing, Intel QSV codecs to video-processing-intel, NVIDIA NVENC codecs to video-processing-nvidia. GPU nodes do not drain the CPU queue. Software renditions above 1080p go to video-processing-heavy instead, which every CPU worker drains with a small pool of its own: one 2160p encode holds what four 1080p ones do, and sharing the common pool's slots let a node start more of them than its memory held.
The rest of the pipeline has its own queues, drained by every worker that is not CHUNKS_ONLY: orchestration (preparation, thumbnail, cleanup), sidecar (audio and subtitle passes) and packaging. See Configuration for the pool sizes.
The dispatcher admits videos per hardware family: each family may have VIDEOS_PER_NODE (five by default) videos in flight per active worker node, plus one. A video holds its slot from the claim until it settles, preparing and packaging included. A full GPU family does not hold back the CPU videos queued behind it. A video whose template needs hardware no active node provides stays pending — it is not failed — and is picked up as soon as such a node comes back.
Error Handling
- Any failure fails the run. A chunk that exhausts its retries, a failed audio/subtitle pass, or a packaging failure marks the video
failed, fails every output that had not completed, cancels the remaining encode batches, and fires thevideo.errorwebhook. The failing rendition'serrorLognames the cause. - Dead workers: jobs retry after a worker is lost.
videos:reap(every minute) fails any active video whose heartbeat has gone stale for longer than one queue redelivery window, unless the queue still owes it work — chunk jobs pending in its batch, a claimed preparation, or a sidecar or packaging job holding its lock. Pending chunk jobs stop protecting it after 12 hours without a heartbeat. - Primary S3 outages: when the source download or the packaging sync fails against primary S3, the job puts itself back on the queue with a growing delay (5, 10, 15… minutes) instead of counting a failure, and
videos:dispatchadmits no new video for ten minutes, so the backlog waits inpendingrather than walking into the same outage. - Upload ingestion:
OnVideoUploadedretries up to 5 times (10s, 30s, 60s, 120s). If it fails for good, the uploaded source is kept rather than deleted, and the upload sweep (every minute, on the API host) dispatches the ingestion once more while the upload's metadata lives. - Retry: a failed video can be requeued with Retry Video or
php artisan videos:retry {id|ulid}…(--reproberebuilds its streams and outputs from the source,--dry-runonly reports). A retry is refused while the failed run still has jobs out or reported progress in the last six minutes. A failure keeps the mirrored source and every staged chunk for a while: the scratch sweep (every 30 minutes) removes them once the video has been failed for 30 minutes. A retry within that window resumes where the run stopped; a later one downloads the source from primary S3 again and encodes it from the start. - Pruning:
videos:prunedeletes videos that have beenfailedfor more than 7 days, their source included. Retry within that window.