interplane.Get Omega
Read in your language

omega-mp4

omega-mp4: ovideo, an MP4 reader written in Omega (Apache-2.0)

Brought by drakestapleton

branch main Branches Tags History

omega-mp4 / README.md

150 lines · 9952 bytes Raw Blame History Source

omega-mp4

ovideo reads MP4 and QuickTime (.mov) files, cuts them and joins them without re-encoding. It is written only in seeded Omega and built by the pinned compiler (see PIN). It follows the public standards ISO/IEC 14496-12 (ISO base media file format; clauses are cited in the source as "14496-12 n.n.n") and the QuickTime file format, which uses the same box (atom) layouts for the boxes read here. Sample data is copied byte for byte from mdat; only the container is rewritten.

ovideo info FILE [DEPTH]        movie and track fields, then the box tree (type, offset, size) to DEPTH (0..16, default 16)
ovideo dump FILE                one line per sample: track, index, decode time, composition offset,
                                duration, size, file offset, sync flag (media ticks)
ovideo trim IN START END OUT    the samples needed to present START..END, moov at the front
ovideo join OUT A B ...         2..16 inputs with matching tracks, one after the other

A time is decimal seconds (12.48, at most 9 fraction digits) that must be a whole number of ticks of the movie timescale (mvhd), or @N for exactly N movie ticks. Other forms exit 1. No floating point is involved, so the cut is exact.

info prints, per track, the handler type, the codec fourcc from the sample description, timescale, duration, sample count, sync sample count, whether ctts is present, the chunk offset form (32 = stco, 64 = co64) and every edit list entry; the movie timescale and duration; and moovpos=front|end.

What trim writes

For every track: from the nearest sync sample at or before START (video), or one packet before the packet holding START (audio, so the decoder has its overlap), to the last sample presented before END, as one contiguous run in decode order, so every reference a kept frame needs is kept. Fresh stts, ctts (when the source has one), stss (when not every sample is a sync sample), stsc, stsz and stco, or co64 when an offset needs 64 bits; durations in mvhd, tkhd and mdhd; an edit list per track (14496-12 8.6.6): an empty edit when the track starts after START, then one media edit whose media time skips the samples before START that were kept only for decoding. Presentation begins exactly at START. A track's own edit list (an empty edit plus one media edit at rate 1) is honoured.

A player that ignores edit lists shows every kept sample from its decode time 0: video starts at the sync sample (up to one GOP before START, and with B-frames the composition offsets are not shifted back), audio starts with the pre-roll packet, and an empty edit (a track that starts late) is lost, so that track is shown early.

join writes the inputs' samples one after the other, each part keeping its own presentation through one media edit per part (plus an empty edit for a gap). ovideo reads such a file with info and dump (editform=complex), but trim and join refuse it with 33.

Build

cat src/io.om src/box.om src/info.om src/plan.om src/write.om src/main.om | OMC > ovideo && chmod +x ovideo

OMC is omega-mv 82e536e1 seed/out/omc, sha256 6d1b1cf5...87f1f8.

Gate

cat tests/gate.om tests/oracle.om | OMC > build/gate-bin && chmod +x build/gate-bin && build/gate-bin OMC

It prints OVIDEOGATE PASS cases=N mutants-killed=K/K robust-runs=R and exits 0, prints FAIL and exits 1, and prints NOT_RUN and exits 3 when the compiler's SHA-256 is not the pin. Oracles (test only, never shipped): ffprobe and ffmpeg 6.1.1. The corpus is generated (corpus/SOURCES.txt, tests/mkcases.om, which also builds the 64-bit cases and the refusal fixtures on every gate run).

Before the cases the gate builds tests/docs.om with the same compiler and runs it: publication checks of the repository's own text (rules in tests/docrules.txt: the licence file and its README section, no local home paths, no notes left from another tool's gate, and the command's earlier name nowhere). It prints DOCS PASS ... mutants-killed=K/K (its own mutants, tests/docmutants.txt), and any other result fails the gate.

Exit codes

CodeMeaning
0done
1usage, or a time that is not a whole number of movie ticks
2cannot open an input
5the output exists or cannot be created (exclusive creation)
20malformed box structure: a size below its header, past its parent or past the file; a version other than 0 or 1
22a required box is missing or repeated
23malformed sample table: counts disagree, a count exceeds its box, a sample outside an mdat
30fragmented file (mvex, moof, mfra, styp, sidx, ssix)
31encrypted or protected track (encv, enca and other protected entries, pssh, senc)
32trim or join with a track other than video or sound (timecode, text, metadata, hint)
33unsupported structure: several sample descriptions, an external data reference, stz2, an edit entry other than an empty edit or a media edit at rate 1; in trim and join also an edit list other than one optional empty edit plus one media edit, or a negative rebased media time
34a bound below is exceeded
35time range: START not below END, or START not below the movie duration
36a track has no sample presented between START and END
40join: different numbers of tracks
41join: handler types differ
42join: sample descriptions are not byte-equal
43join: media timescales differ, or a movie timescale does not convert exactly
60I/O error reading an input, writing the output or writing standard output

Every refusal prints one line ovideo: ... on standard error. After a refusal the output file does not exist (it is created only after every check, exclusively, and removed if a later write fails).

Bounds (each refused with 34, never a trap)

Samples held, all tracks and inputs together, 1048576. Tracks 8 per input, track slots 128. Inputs per join 16. Edit list entries 64 per input track and 64 per output track. Chunks 1048576. Boxes 65536 per walk, nesting depth 16. Sample description box 1 MiB. Output moov 16 MiB. Table entry counts 1048576. Static arrays only, no heap. Every loop over file structure is bounded by a checked count or by the file size; the input is read through a 1 MiB pread window and copied in 4 MiB pread/write blocks.

Throughput

MEASURED 2026-11-10, Linux AArch64 (the Spark), one core (taskset -c 10, pool-10-11), load about 14, warm page cache: a 212307829-byte file (120 s, 1280x720 H.264 + AAC), whole-range trim including fsync, median of 3: 357.1 ms, 566.9 MiB/s. Plain cp of the same bytes 96.1 ms (2106.6 MiB/s, no fsync); dd conv=fsync 234.8 ms (862.4 MiB/s). Trim takes 1.52 times the fsynced copy.

Not supported in this slice

Fragmented files (moof), encryption, decoding or re-encoding of any codec, frame-exact cuts without an edit list, subtitle, timecode and metadata tracks (refused, not dropped), HEIF and other image collections, trim or join of files with several media edits per track, udta/meta/tref boxes (not copied; track IDs are renumbered). The writer's co64 and largesize output paths need an output above 4 GiB and are not exercised; input files above 4 GiB are (a sparse case).

Licence

Apache License 2.0; the full text is in LICENSE.