From 404ed7aa57c9f1559853d167cdfa5043c680c306 Mon Sep 17 00:00:00 2001 From: Carlos Fernandez Date: Sat, 17 Oct 2026 17:34:10 -0700 Subject: [PATCH] Compute FFmpeg tx3g end time in one step #2378 derives the end of a tx3g cue as start_ms + duration * 1000 / timescale. Both terms are truncated separately, so the end can land 1 ms before the GPAC path's, which converts pts + duration at once. On a real m4v with 797 cues, 99 ended 1 ms early (e.g. timescale 600, pts 135725, duration 2725: 230749 instead of 230750). --- src/rust/src/demuxer/mp4.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rust/src/demuxer/mp4.rs b/src/rust/src/demuxer/mp4.rs index fc3151892..275da15cc 100644 --- a/src/rust/src/demuxer/mp4.rs +++ b/src/rust/src/demuxer/mp4.rs @@ -401,8 +401,11 @@ pub unsafe fn processmp4_rust(ctx: *mut lib_ccx_ctx, path: &CStr, sub: *mut cc_s // the global timing pointer may already be past this subtitle // because packets from every track are interleaved. let start_ms = pts * 1000 / timescale as i64; + // Convert the end point in one step, as the GPAC path does; + // adding separately truncated start and duration can land + // 1 ms early. let end_ms = if pkt.duration > 0 { - start_ms + pkt.duration * 1000 / timescale as i64 + (pts + pkt.duration) * 1000 / timescale as i64 } else { -1 };