Nudge non-monotonic source DTS instead of crashing the mux - #353
Open
ironicgitposting wants to merge 1 commit into
Open
ironicgitposting wants to merge 1 commit into
ironicgitposting wants to merge 1 commit into
Conversation
Sloppy source files (e.g. web remuxes with 1/1000 audio time bases) can carry duplicate or backwards DTS in their audio/subtitle streams. The copy path in _pump_source_streams muxed those packets verbatim, and the mp4 muxer hard-fails with 'non monotonically increasing dts', killing the whole job partway through. Track the last muxed DTS per output stream and nudge offending packets forward by one tick, mirroring what ffmpeg's CLI muxer does and what _clamp_pts_monotonic already does for the video stream. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Fixes #352.
Problem
_pump_source_streamsmuxes copied source packets verbatim. If the source audio (or subtitle) stream carries a duplicate/backwards DTS — common in web remuxes with 1/1000 audio time bases — the mp4 muxer hard-fails withnon monotonically increasing dts to muxerand the whole job dies, potentially hours in. Deterministic: same packet, same crash, every run.Fix
New
_mux_source_packethelper tracks the last muxed DTS per output stream and nudges an offending packet forward by one tick (pts pulled up alongside if needed), then logs a warning. This mirrors what ffmpeg's CLI muxer does with such files, and what_clamp_pts_monotonicalready does for the encoded video stream. Used by both the pump loop and_drain_source_streams' transcode flush.Per-stream state lives in
_setup_source_streamsnext to the rest of the pump state.Testing
test_pump_nudges_non_monotonic_dts(duplicate DTS 370390 — the real-world value from the file I hit this on — comes out 370390, 370391 with pts matched).tests/test_video_encoder_unit.py: 109 passed; the 3 failures (TestSharpening×2,TestEncodeBuffer) also fail on a clean checkout in my env (CPU-only torch, no CUDA) and are unrelated.🤖 Generated with Claude Code