Repository navigation
fix(video): prime moov from a real audio frame when the first segment has none (#222) - #224
Merged
Merged
Conversation
… has none An E-AC-3 source whose first segment carries no audio packet never produced a frame: movenc builds the ec-3 sample entry's dec3 box in handle_eac3, i.e. only from a PARSED bitstream frame, never from codecpar or extradata. Under +delay_moov the moov is written at the first fragment flush, so a first cut with video only fails -22 "Cannot write moov atom before EAC3 packets parsed", completedBytes stays 0, and the cut reported failure. flushPendingFragment already refuses that flush; the cut did not, and its only "not now" signal was nil, which the producer reads as a fatal wedge. The VOD revive then rebuilt the identical configuration twice more and gave up, so the host fell back to a server transcode of a file it should have played untouched. Reproduced deterministically with a synthetic MKV whose audio starts behind ~12 s of video (HEVC Main10 + E-AC-3 5.1): packetsRead=95 packetsWritten=93, three identical failures, then "source not muxable in this session". The EAC3 bridge wedges the same way (its encoder output is also E-AC-3); only the FLAC bridge played, at the cost of the passthrough. A cut now has a third outcome, deferredAwaitingAudioSampleEntry: nothing is written and the muxer stays intact. The pump treats it as recoverable, scans forward for one real audio frame (bounded, discarding everything else), and exits with that frame. The host stores it for the whole session and rebuilds: every muxer from then on muxes the frame at init, which writes moov with a genuine dec3, then discards the primed fragment's bytes. The delivered segment is therefore unchanged (no out-of-place audio sample, no disjoint track ranges, plan boundaries untouched) and the E-AC-3 stream-copy, Atmos included, is kept. Re-arming +frag_discont after the prime is load-bearing: movenc consumes the flag on the primed packet and would then rewrite each track's next fragment-opening sample to start_dts + track_duration, so the first real audio fragment landed at tfdt 0 regardless of where its samples belong (measured on the fixture: a 12 s audio start rendered 12 s early). Re-armed, timestamps match an unprimed session exactly, verified on the produced segments: seg0 video-only at 0.000s, seg3 video 11.792s + audio 11.995s, seg4 continuous. finalize() gets the same precondition, so a teardown on a never-primed muxer stops emitting -22s for a moov it cannot write. Sources whose audio arrives normally are untouched: the control fixture primes nothing, logs nothing, and keeps byte-identical fragment timestamps. Reported and root-caused by thatcube, who pinned the missing guard in cutFragmentForNextSegment and ruled out both dec3-in-extradata and dropping +delay_moov. Co-Authored-By: thatcube <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An E-AC-3 source whose first segment carries no audio packet never produces a frame. movenc builds the
ec-3sample entry'sdec3box inhandle_eac3, i.e. only from a PARSED bitstream frame, never from codecpar or extradata (#222 verified: a validdec3in extradata still returns -22). Under+delay_moovthe moov is written at the first fragment flush, so a first cut with video only fails -22 "Cannot write moov atom before EAC3 packets parsed",completedBytesstays 0, and the cut reported plain failure.flushPendingFragmentalready refuses that flush.cutFragmentForNextSegmentdid not, and its only "not now" signal was nil, which the producer reads as a fatal wedge: the VOD revive rebuilt the identical configuration twice more, gave up with "source not muxable in this session", and the host fell back to a server transcode of a file it should have played untouched.Repro
Synthetic MKV, HEVC Main10 + E-AC-3 5.1, audio starting behind ~12 s of video in file order (
-itsoffset), which reproduces the reporter's trace exactly:The EAC3 bridge wedges identically (its encoder output is also E-AC-3). Only the FLAC bridge played, at the cost of the passthrough, which is why bridging is not the fix.
Fix
deferredAwaitingAudioSampleEntry: nothing written, muxer intact.dec3, then discards the primed fragment's bytes. The delivered segment is unchanged: no out-of-place audio sample, no disjoint track ranges, plan boundaries untouched, E-AC-3 stream-copy and Atmos preserved.finalize()gets the same precondition, so a teardown on a never-primed muxer stops emitting -22s for a moov it cannot write.Why re-arming +frag_discont is load-bearing
movenc consumes the flag on the primed packet, after which each track's next fragment-opening sample is rewritten to
start_dts + track_duration, andtfdtiscluster[0].dts - start_dts. Un-rearmed, the first real audio fragment lands at tfdt 0 no matter where its samples belong: measured on the fixture, a 12 s audio start rendered 12 s early. Re-armed, timestamps match an unprimed session exactly.Verification
Issue222EAC3MoovPrimeTests(6 tests): deferral instead of failure, AAC unaffected,dec3present in the primed init, primed fragment not served, video-only first segment cuts, and the tfdt regression (proven to fail without the re-arm:tfdt=[-1024, 0]instead of 576000).audioTrack codec='ec-3', first frame 0.15 s, 20 s of playback with no stall,VERDICT: OK. Produced segments: seg0 video-only at 0.000s, seg3 video 11.792s + audio 11.995s, seg4 continuous. 40-seek burst settles at 0.00s error with no second defer.Reported and root-caused by @thatcube, who pinned the missing guard and ruled out both dec3-in-extradata and dropping
+delay_moov.Refs #222
🤖 Generated with Claude Code
https://claude.ai/code/session_01QYhPvBB1sLCYoZNasEXFeB