From 5f41c0bd65363c23d13cf20de00288513a0e61c9 Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Wed, 10 Feb 2016 12:12:32 -0700 Subject: [PATCH] sync: fix subtitle timestamps that go backwards This should be really difficult to trigger, but someone found a sample that does. --- libhb/sync.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libhb/sync.c b/libhb/sync.c index 69cad65de..e3508130d 100644 --- a/libhb/sync.c +++ b/libhb/sync.c @@ -59,6 +59,7 @@ typedef struct int merge; hb_buffer_t * list_current; hb_buffer_t * last; + int64_t last_start; } subtitle_sanitizer_t; typedef struct @@ -229,6 +230,7 @@ static void InitSubtitle( hb_job_t * job, hb_sync_video_t * sync, int i ) // Fill in stop time when it is missing sync->subtitle_sanitizer[i].link = 1; } + sync->subtitle_sanitizer[i].last_start = AV_NOPTS_VALUE; } static void CloseSubtitle(hb_sync_video_t * sync, int ii) @@ -512,7 +514,20 @@ static hb_buffer_t * sanitizeSubtitle( sanitizer->last = sub; } } - return mergeSubtitles(sanitizer, 0); + + hb_buffer_t * out; + sub = out = mergeSubtitles(sanitizer, 0); + while (sub) + { + if (sub->s.start < sanitizer->last_start) + { + sub->s.start = sanitizer->last_start; + } + sanitizer->last_start = sub->s.start; + sub = sub->next; + } + + return out; } /*********************************************************************** -- 2.40.0