From 9307acf7fa36bf49d762c0d180c9fb0e7bfcb13a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 15 Dec 2022 18:52:47 +0200 Subject: [PATCH] mp4mux: Fix edit list shift for streams with initial DTS smaller earliest PTS but initial DTS positive This would be a stream where the initial DTS is negative if the initial PTS was zero, but it is offset so the initial DTS became positive now. The edit list shift has to happen exactly the same way though. Part-of: --- mux/mp4/src/mp4mux/boxes.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mux/mp4/src/mp4mux/boxes.rs b/mux/mp4/src/mp4mux/boxes.rs index 4309c9cd..9db658ee 100644 --- a/mux/mp4/src/mp4mux/boxes.rs +++ b/mux/mp4/src/mp4mux/boxes.rs @@ -1683,9 +1683,11 @@ fn write_elst( v.extend(duration.to_be_bytes()); // Media time - if let Some(gst::Signed::Negative(start_dts)) = stream.start_dts { - let shift = (stream.earliest_pts + start_dts) + if let Some(start_dts) = stream.start_dts { + let shift = (gst::Signed::Positive(stream.earliest_pts) - start_dts) .nseconds() + .positive() + .unwrap_or(0) .mul_div_round(timescale as u64, gst::ClockTime::SECOND.nseconds()) .context("too big track duration")?;