Skip to content

Native codecs (experimental) ​

By default Chrome decodes the footage and encodes the export. The native codecs can do either job, or both, in place of Chrome. They run in uberscene-codec, a small Rust process built on FilmCraft's codecs, craft-video, craft-audio and craft-media. These are pure Rust and need no FFmpeg. The player still draws every frame in the page. Only the decoding and the encoding move, the sound's included.

This page covers how pictures and sound get to the process and back, and which formats it reads and writes. To turn it on, Exporting has UBERSCENE_CODECS and the commands.

Experimental

The native codecs run only when UBERSCENE_CODECS asks for them, and Chrome stays the default. The first native export downloads them, and on a CPU they are not faster than Chrome yet.

How data flows ​

text
page                                  Node (the export's server)          uberscene-codec (one process per stream)
────                                  ──────────────────────────          ────────────────────────────────────────
NativeFrameSource ── /native/frames ─► reads the asset's file ──────────► decode → I420 pictures on stdout
   VideoFrame ◄────── streamed back ── pipes stdout to the page
capture → RGBA ───── /native/encode ─► writes pictures in order ────────► encode (H.264, ProRes) → packets
                                      keeps the packets for the join ◄──
                                      mixPlan (with native) ◄──────────── decode-audio → float PCM
mix as float WAV ── (native-encode) ──► the mix, interleaved ────────────► encode-audio → M4A or WAV
                                      muxed with the pictures ◄─────────

For each stream, Node starts one uberscene-codec, writes to its stdin and reads its stdout. If the process exits with an error, Node reads the error from stderr. Numbers on the wire are little-endian. native/PROTOCOL.md in the repository lists every byte.

Getting the binary ​

The first export with UBERSCENE_CODECS downloads uberscene-codec for your machine from this version's GitHub release into ~/.cache/uberscene/codecs/<version>/ (UBERSCENE_CODEC_CACHE moves it), the way Chrome is downloaded. To download it ahead, in a Dockerfile or a CI step:

sh
npx uberscene codecs install

Binaries are released for macOS (Apple silicon and Intel), Linux x64 and arm64 (glibc) and Windows x64. Each download is checked against the SHA-256 the npm package carries, so a binary is used only if it is the one the release built. The version is always the export's own: the two speak a protocol that changes between releases.

On another platform (Alpine, Windows on arm64), build it from the repository: pnpm native:build with Rust 1.95 or later writes native/target/release/uberscene-codec. Name it in UBERSCENE_CODEC_BIN.

The export takes the first of: UBERSCENE_CODEC_BIN; in a checkout of the repository, the binary pnpm native:build made; this version's binary in the cache, downloaded if it is not there yet.

Decoding ​

  1. Probe. uberscene-codec probe <file> prints one line of JSON: the display size (after rotation), duration, frame rate, codec, and whether the first picture actually decoded.
  2. Stream. The page's NativeFrameSource asks the export server for /native/frames/<asset>, either a range (--from, --to) or a single time (--at). The server runs uberscene-codec decode on the asset's file and pipes its stdout straight back to the page.
  3. Wrap. Each picture is a 32-byte header (size, colour matrix, range, time, duration) followed by 8-bit I420 planes. The page turns each one into a VideoFrame, and the player draws it like a frame Chrome decoded.

When the page stops reading, the server closes the stream and the process stops. Decoding plugs into the player's FrameSource seam (How the player draws), so the compositor, the effects and the capture stay the same.

If probing says an asset can't be decoded, or the asset comes from a URL, Chrome decodes it instead, with one warning. Images always stay in the browser; the sound is under Sound.

Encoding ​

  1. Read back. For each piece, the page copies each captured picture out as RGBA (VideoFrame.copyTo).
  2. Post. It posts the picture to /native/encode/<session>, with at most two in flight.
  3. Encode. The server writes each picture to uberscene-codec encode as a 16-byte header plus the RGBA bytes. The process writes the decoder configuration first (an avcC record for H.264), then one packet per picture with its keyframe flag and timestamps.
  4. Join. Node keeps the packets and writes them into the file with the other pieces. They never pass through the page.

The H.264 encoder writes no B-frames, and puts keyframes only at the start of each keyframe interval. Each piece is a whole number of intervals, so the pieces join without re-encoding, the same as with Chrome (Pieces and pages). Every ProRes packet is a keyframe.

Sound ​

With a native encoder, uberscene-codec encode-audio writes the soundtrack: it reads the mix as interleaved float on stdin and writes the whole file when the input ends. Who mixes depends on who decodes:

  • native: Node runs mixPlan, the page's own mixer, so volume, fades, ducking, pan and speed sound the same. Its sound comes from uberscene-codec decode-audio: each range planar float at the file's own rate, silence where the file has none. Decoding starts 120 ms before the range and drops the warm-up, so a decoder started mid-stream gives what a decode from the start gives. The page plays no part in the sound.
  • native-encode: the page mixes as with Chrome and hands the mix over as a WAV of 32-bit float, which Node feeds to the encoder.

An asset whose sound the native decoder cannot read (FLAC, Vorbis, or one served from a URL) sends the whole mix back to the page, with one warning. An MP3 export keeps Chrome's encoder, since the native MP3 has no gapless header yet.

Formats ​

DecodesContainers
H.264, HEVC (8 and 10 bit)MP4/MOV, Matroska/WebM
VP8, VP9, AV1MP4/MOV, Matroska/WebM
ProRes, DNxHD/DNxHRMP4/MOV, Matroska/WebM
EncodesInto
H.264, High profile, BT.709 limited rangeMP4
ProRes: Proxy, LT, 422, 422 HQ, 4444MOV (--codec prores; --quality picks the profile)
Sound decodesContainers
AAC, Opus, MP3, AC-3/E-AC-3, ALAC, PCMMP4/MOV, Matroska/WebM, Ogg, WAV, AIFF, raw ADTS and MP3
Sound encodesFor
AAC-LC in an M4A, its edit list trimming the encoder's primingMP4
24-bit PCMMOV
16-bit PCMWAV

Pictures reach the page as 8-bit 4:2:0. Higher bit depths and 4:2:2/4:4:4 are converted, alpha is dropped, and a rotated file is turned upright. What the native codecs leave to Chrome is listed under Exporting.

Next ​

MIT licensed.