Перейти к содержимому

EP09[mp4]: Finale: build dump

The Shadow Brains

0:00 / 0:00

EP09[mp4]: Finale: build dump

8 просмотров · 10 дн. назад
The Shadow Brains
10 подписчиков
8 просмотров · 10 дн. назад
Season 1's finale. Episode 6 stepped over phone.mp4's moov: one crate, 3,412 bytes. Today we open all of it. A crate full of crates: how does a reader know which crates to open, and where each one inside begins and ends? By the end our own tool, mp4kit dump, prints the whole box tree of every test file, and we check it against ffprobe's own walk. What you'll learn • Container boxes and leaf boxes: a container's crates start right after its lid (moov at 108,744: mvhd at 108,744 + 8 = 108,752) and fill it exactly to its end (108,752 + 108 = 108,860 trak, + 1,454 = 110,314 trak, + 1,781 = 112,095 udta, + 61 = 112,156 = moov's end). Nothing on the lid says "I hold crates": only the type does, so a reader keeps a list (mp4kit's has 14 types; phone.mp4 uses 8) • The walk as a state machine: READ LID, STEP IN, JUMP, DONE. Walked by hand down phone's first trak, where stco, stbl, minf, mdia and trak all end at the same byte, 110,314. The parent's end is also a check: a crate must fit inside its parent, not just inside the file • Doors with a step: some crates hold fields before their first child. stsd and dref 8 bytes (a stamp and entry_count), meta 4, the video entries (avc1) 78, the sound entries (mp4a) 28: avc1 at 109,169 + 8 + 78 = 109,255, avcC; mp4a at 110,619 + 8 + 28 = 110,655, esds • Checking the plan: ffprobe -v trace names 52 boxes in phone.mp4, our walk 56. Every box ffprobe names, our walk names too, with the same type and size, in the same order; ffprobe leaves out the two sample entries (avc1, mp4a) and the two url boxes, and gives five boxes the parent stsd. On broken-nomoov.mp4 ffprobe gives up (moov atom not found, exit 1); our dump shows ftyp, free, mdat, then "no moov box" • Build it: mp4kit learns CONTAINERS, CHILD_OFFSET, the recursive walk, read_mp4 and the dump command (tag ep09): phone.mp4's 56 lines, avcC seven levels in, and all 16 test files without an error. The tag's 8 tests and the season's 68 pass The example files: phone.mp4, broken-nomoov.mp4, f1.mp4 and the other 13 test files in mp4kit's testfiles/out/. Every number on screen comes from these files. Example files and commands: https://github.com/askshadowbrain-sys... Commands shown (in film order; in mp4kit's testfiles/out/, after git checkout ep09 and, from the repo root, export PYTHONPATH=$PWD and alias mp4kit='python3 -m mp4kit'; the dump before Build it is last week's tool: run it after git checkout ep08 -- mp4kit, then git checkout ep09 -- mp4kit for the rest; the ffprobe line with PIPESTATUS needs bash) • xxd -s 108744 -l 24 phone.mp4 • xxd -s 109153 -l 32 phone.mp4 • xxd -s 109169 -l 96 phone.mp4 • xxd -s 110603 -l 60 phone.mp4 • xxd -s 109117 -l 28 phone.mp4; xxd -s 112103 -l 20 phone.mp4 • ffprobe -v trace phone.mp4 |& grep "type:'" | sed 's/ @ 0x[0-9a-f]*//' • ffprobe -v error broken-nomoov.mp4 |& sed "s/ @ 0x[0-9a-f]*//"; echo "exit ${PIPESTATUS[0]}" • mp4kit dump phone.mp4; echo "exit $?" • mp4kit dump phone.mp4 • mp4kit dump broken-nomoov.mp4; echo "exit $?" • mp4kit dump f1.mp4 • for f in *.mp4 *.m4a; do echo "$ mp4kit dump $f"; mp4kit dump $f; echo; done (In the film the two ffprobe commands send stderr into the pipe with a redirect, and the first mp4kit dump joins its stderr to its output; YouTube descriptions can't hold that character, so the ffprobe lines are shown here with |&, which does the same in zsh and in bash 4 or later, and the mp4kit line without the redirect: its error reaches the terminal either way. The PIPESTATUS line needs bash; macOS's own /bin/bash 3.2 has no |&, so there type the redirect as the film shows it.) The tag's tests and the whole season's suite, from the repo root at tag ep09 (with PYTHONPATH set as above): python3 -m unittest -v tests.test_ep09, then python3 -m unittest. The comparison of ffprobe's trace with our walk, the container and step tables, and the parent check (tkhd's size set to 2,000 in a copy in memory) are shown as tables and code; the tag's tests run the same checks (test_walk_matches_ffprobe_trace, test_tables, test_child_overrunning_parent_raises). Voice: AI text-to-speech (ElevenLabs "Alice"), one voice for every line, presenter and narration. Presenter visuals: AI-generated (Gemini) and lip-synced locally (MuseTalk 1.5). Every number on screen comes from real runs on the example files (xxd, ffprobe and mp4kit at tags ep08 and ep09). Music: original, generated with ElevenLabs Music; the intro sound is synthesised in code. Previous episode: EP08[mp4] — ftyp and brands:    • EP08[mp4]: ftyp and brands   Season 2 opens the map room, moov, starting with mvhd's clock (EP10). The whole series, in order: the MP4 from Scratch playlist. Chapters 0:00 Crates in crates 5:07 The walk 9:15 Doors with a step 13:44 Checking the plan 16:05 Build it #mp4 #python #video