Conversation
Downloading a stream with >=1800 segments always ran PartialCombineMultipleFiles first, which byte-splices every 100 segments into a single T####.ts intermediate. ffmpeg then reads each intermediate as one continuous stream and cannot see the timestamp resets that occur inside it, so the merged file keeps all its data but gets a broken timeline (reported as ~33 minutes for a 142-minute movie, with a flood of "Non-monotonic DTS" warnings). Partial merge only exists to protect the concat *protocol* path, which opens every segment at once (nilaoda#338, nilaoda#89) and puts every file name on the command line. The concat *demuxer* has neither limit: MergeByFFmpeg writes the file list to a temp file and ffmpeg opens the segments one at a time. There it is pure downside - it corrupts timestamps, doubles peak disk usage and adds a full extra copy pass. So skip it when --use-ffmpeg-concat-demuxer is used. Behaviour of the concat protocol path is unchanged. Verified on a locally served 1900-segment HLS playlist whose segments each restart at PTS 0: before, --use-ffmpeg-concat-demuxer: 19.56s (expected 1944.12s) after, --use-ffmpeg-concat-demuxer: 1944.14s before/after, without the flag: 1900.04s (identical) Co-Authored-By: Claude Opus 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 #946.
Problem
Downloading a stream with >=1800 segments always runs
PartialCombineMultipleFilesbefore the ffmpeg merge, which byte-splices every 100 segments into a singleT####.tsintermediate. ffmpeg then reads each intermediate as one continuous stream and cannot see the timestamp resets that occur inside it, so the merged file keeps all of its data but ends up with a broken timeline — the reporter's 2140-segment / 142-minute movie muxes to 955 MB but reports ~33 minutes, with a flood ofNon-monotonic DTSwarnings.This happens even with
--use-ffmpeg-concat-demuxer, so there is currently no option combination that produces a correct file for long content whose segments contain timestamp resets (movies, TV recordings).Why the partial merge is not needed here
Partial merge exists to protect the concat protocol path, which opens every segment at once (#338, #89) and puts every file name on the command line.
The concat demuxer has neither limit:
MergeUtil.MergeByFFmpegwrites the file list to a temp file (-f concat -safe 0 -i <list>) and ffmpeg opens the segments one at a time. In that mode the partial merge is pure downside — it corrupts timestamps, doubles peak disk usage, and adds a full extra copy pass over every segment.Change
Skip the partial merge when
--use-ffmpeg-concat-demuxeris used. The threshold and the reasoning now live next toPartialCombineMultipleFilesasMergeUtil.ShouldPartialMerge. Behaviour of the concat protocol path is completely unchanged: no new options, no default changes, no resource-string changes.Verification
Locally served 1900-segment HLS playlist whose segments each restart at PTS 0 (playlist total 1944.12s):
--use-ffmpeg-concat-demuxerNon-monotonic DTSfloodPossible follow-ups (not in this PR)
MergeByFFmpegonly warns).