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.
- info: every field against
ffprobe -show_streamsand the oracle's own box reader (mvhd, tkhd, mdhd, hdlr, elst, ctts). The box reader also refuses a version-0cttsentry at or above 2^31: version 0 offsets are unsigned (14496-12 8.6.1.3), so such a word is a negative offset written in the wrong version, which ffmpeg decodes anyway (it reads every ctts as signed). corpus/negcts.mp4 has negative composition offsets (ctts version 1), so trim, join and whole-range trim exercise the version-1 writer. dump: every sample againstffprobe -ignore_editlist 1 -show_packets(position, size, DTS, PTS, flags, SHA-256 of the data); a sample's duration is the next DTS minus this one, the last one's the last stts delta, because ffprobe's packet duration is an estimate (MEASURED: 1 instead of 20 on vonly.mov). ffprobe's DTS are taken back to the file's decode times (DT(0) = 0, 14496-12 8.6.1.2): with negative composition offsets ffmpeg moves every DTS of the track down by the largest of them (MEASURED on negcts.mp4: first video packet dts=-512, pts=0). - trim and join: the output's packet list must equal the source packets the documented selection keeps,
in order, with equal data hash, size, flags and composition offset, decode times rebased; the output edit
lists and durations must be exactly the computed ones;
ffmpeg -xerrordecodes it with empty stderr; the decoded video frames (framemd5) equal the source frames presented in START..END (for join, the parts' frames in order); the decoded audio (s16le) equals the source samples from START. - Difference class
pns-audio-not-compared: AAC coded with perceptual noise substitution decodes from a pseudo-random generator whose state runs through the stream, so a cut decodes about 1 LSB apart from the same range of the whole file (MEASURED: 6358 of 123536 bytes; without PNS 0). For corpus/pns.mp4 packets and video are compared, decoded audio is not. - ffmpeg does not cut decoded AAC at the end of an edit, so audio is compared over the decoded length.
- Mutants (each must fail a named case): chunk offsets not rebased, sync table not rebuilt, edit media time one sample off, ctts dropped, stsc samples per chunk wrong, a 64-bit chunk offset truncated to 32 bits, negative composition offsets written in a version-0 ctts, the stderr prefix changed.
- Robustness: every corpus file cut at 64 points and changed at 256 single bytes, whole-range trim of each, 10 s limit: exit 0 or a documented code, never a trap, signal or time-out, and no output left after a refusal. The sparse file is copied with its holes.
Exit codes
| Code | Meaning |
|---|---|
| 0 | done |
| 1 | usage, or a time that is not a whole number of movie ticks |
| 2 | cannot open an input |
| 5 | the output exists or cannot be created (exclusive creation) |
| 20 | malformed box structure: a size below its header, past its parent or past the file; a version other than 0 or 1 |
| 22 | a required box is missing or repeated |
| 23 | malformed sample table: counts disagree, a count exceeds its box, a sample outside an mdat |
| 30 | fragmented file (mvex, moof, mfra, styp, sidx, ssix) |
| 31 | encrypted or protected track (encv, enca and other protected entries, pssh, senc) |
| 32 | trim or join with a track other than video or sound (timecode, text, metadata, hint) |
| 33 | unsupported 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 |
| 34 | a bound below is exceeded |
| 35 | time range: START not below END, or START not below the movie duration |
| 36 | a track has no sample presented between START and END |
| 40 | join: different numbers of tracks |
| 41 | join: handler types differ |
| 42 | join: sample descriptions are not byte-equal |
| 43 | join: media timescales differ, or a movie timescale does not convert exactly |
| 60 | I/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.