Skip to main content

Crate mp4_muxer

Crate mp4_muxer 

Source
Expand description

§mp4_muxer

A tiny, dependency-free MP4 muxer for AV1 video streams.

Given a sequence of AV1 OBU packets — one per frame — this crate produces an ISO Base Media File Format (ISOBMFF / MP4) container playable by browsers, VLC, QuickTime, and every other mainstream player.

§What it does

  • Writes a valid, seekable .mp4 in a single pass.
  • Uses AV1 (av01) as the video codec.
  • Handles files larger than 4 GiB by transparently switching to 64-bit chunk offsets (co64 instead of stco).
  • Zero runtime dependencies.

§What it doesn’t do

  • No audio track.
  • No B-frames / re-ordering: the muxer assumes every frame is displayed in the order it was written (pts == dts).
  • No fragmented MP4 (fMP4 / DASH / HLS) output.
  • Doesn’t inspect the AV1 bitstream — you must correctly tag keyframes.

§Output layout

ftyp  — file type box (isom / av01)
mdat  — raw AV1 OBU packet data
moov  — movie metadata
  mvhd — movie header
  trak — video track
    tkhd — track header (width, height)
    mdia
      mdhd — media header
      hdlr — handler type = "vide"
      minf
        vmhd — video media header
        dinf → dref — self-contained data reference
        stbl — sample table
          stsd → av01 → av1C
          stts — sample durations
          stss — sync (keyframe) sample indices
          stsc — sample-to-chunk mapping
          stsz — sample sizes
          stco / co64 — chunk offsets (absolute file positions)

Because mdat comes before moov, chunk offsets are known at finalisation time — no second-pass rewrite of the file is needed.

§Usage

use mp4_muxer::Mp4Writer;
use std::fs::File;

let file = File::create("output.mp4")?;
let mut muxer = Mp4Writer::new(file, 1920, 1080, 30, 1)?;

for i in 0..n_frames() {
    let obu = get_obu(i);
    let is_keyframe = i == 0;
    muxer.write_frame(&obu, is_keyframe)?;
}

muxer.finish()?;

Structs§

Mp4Writer
Incremental MP4 muxer for AV1 OBU streams.

Enums§

Error
Errors returned by Mp4Writer.

Type Aliases§

Result
Convenient result alias for the muxer’s public API.