From 74271a7d80f6c59185699d0d6d2d0b64bcbe90ae Mon Sep 17 00:00:00 2001 From: Ricardo Fonseca Date: Thu, 28 May 2026 00:04:39 +0100 Subject: [PATCH] sub/sd_ass: subtitle timing rounding errors Use floor(pts * 1000 + 1e-6) instead of llrint() for all timestamp conversions to avoid floating-point precision errors causing early subtitle presentation on boundry frames. Fixes: #17453 Signed-off-by: Ricardo Fonseca --- sub/sd_ass.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sub/sd_ass.c b/sub/sd_ass.c index d415106caf..9d03137c61 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -386,8 +386,8 @@ static void filter_and_add(struct sd *sd, struct demux_packet *pkt) } ass_process_chunk(ctx->ass_track, pkt->buffer, pkt->len, - llrint(pkt->pts * 1000), - llrint(pkt->duration * 1000)); + floor(pkt->pts * 1000 + 1e-6), + floor(pkt->duration * 1000 + 1e-6)); // This bookkeeping only has any practical use for ASS subs // over a VO with no video. @@ -663,7 +663,7 @@ static long long find_timestamp(struct sd *sd, double pts) if (pts == MP_NOPTS_VALUE) return 0; - long long ts = llrint(pts * 1000); + long long ts = floor(pts * 1000 + 1e-6); if (!sd->opts->sub_fix_timing || sd->shared_opts->ass_style_override[sd->order] == ASS_STYLE_OVERRIDE_NONE) @@ -1061,7 +1061,7 @@ static int control(struct sd *sd, enum sd_ctrl cmd, void *arg) switch (cmd) { case SD_CTRL_SUB_STEP: { double *a = arg; - long long ts = llrint(a[0] * 1000.0); + long long ts = floor(a[0] * 1000.0 + 1e-6); long long res = ass_step_sub(ctx->ass_track, ts, a[1]); if (!res) return false;