Skip to content

fix(video): clamp corrupt live remux PTS/DTS pairs - #554

Merged
Linuxuser67 merged 1 commit into
mainfrom
fix/live-remux-pts-dts-clamp
Oct 27, 2026
Merged

Linuxuser67 merged 1 commit into
mainfrom
fix/live-remux-pts-dts-clamp

Conversation

@Linuxuser67

Copy link
Copy Markdown
Owner

What

Live recordings that hit a timeline discontinuity (for example a Twitch ad break) failed at finalize with:

[mp4] pts/dts pair unsupported
[out#0/mp4] Error writing trailer: Not yet implemented in FFmpeg, patches welcome

Why

At the ad-to-content jump, the first two post-jump video packets carry the new PTS but no PES DTS. FFmpeg synthesises DTS from the pre-jump reorder buffer, leaving a PTS/DTS difference of about 5.28e9. movenc rejects any pair that does not fit a signed 32-bit delta. FFmpeg CLI discontinuity correction only starts at the third post-jump packet, so those two survive and abort the remux.

Fix

Add a setts input BSF for video remuxes. It is a no-op for normal packets and resets only pairs whose difference exceeds ten minutes at the 90 kHz MPEG-TS timebase, after FFmpeg discontinuity correction and before the interleaver. Audio-only remuxes skip it. A regression test pins the input-scoped placement and the audio-only exclusion.

Reproduced with a 30 s capture and the Flatpak FFmpeg 8.1.3: the exact failing argv now exits 0 with a 43.5 s MP4 whose A/V stay aligned across the seam. CI is the verification for the Rust change.

A live capture that jumps timeline mid-file (for example across a Twitch
ad break) leaves the first two post-jump video packets with the new PTS
and a DTS synthesised from the pre-jump reorder buffer. Their difference
overflows movenc's signed 32-bit check, so the live remux fails at the
trailer with "pts/dts pair unsupported".

Run setts as an input BSF on video remuxes. It leaves normal packets
alone and resets only pairs whose difference exceeds ten minutes at the
90 kHz MPEG-TS timebase, before the interleaver reaches the muxer.
@Linuxuser67
Linuxuser67 merged commit c534e1b into main Oct 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant