]> granicus.if.org Git - handbrake/commitdiff
sync: fix subtitle timestamps that go backwards
authorJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 10 Feb 2016 19:02:44 +0000 (12:02 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Wed, 10 Feb 2016 19:02:44 +0000 (12:02 -0700)
This should be really difficult to trigger, but someone found a sample
that does.

libhb/sync.c

index dd8c54adca3cf7f6976ab7dac687010b7c0fedb3..282c18bbd428dc21d4b9c86ae6dcf4abbbcefbe5 100644 (file)
@@ -736,9 +736,18 @@ static void streamFlush( sync_stream_t * stream )
             {
                 buf->s.start = stream->next_pts;
                 buf->s.stop  = stream->next_pts + buf->s.duration;
+                stream->next_pts += buf->s.duration;
+            }
+            else
+            {
+                // Last ditch effort to prevent timestamps from going backwards
+                // This can (and should only) affect subtitle streams.
+                if (buf->s.start < stream->next_pts)
+                {
+                    buf->s.start = stream->next_pts;
+                }
+                stream->next_pts = buf->s.start;
             }
-
-            stream->next_pts += buf->s.duration;
 
             if (buf->s.stop > 0)
             {
@@ -967,9 +976,19 @@ static void OutputBuffer( sync_common_t * common )
             {
                 buf->s.start = out_stream->next_pts;
                 buf->s.stop  = out_stream->next_pts + buf->s.duration;
+                out_stream->next_pts += buf->s.duration;
+            }
+            else
+            {
+                // Last ditch effort to prevent timestamps from going backwards
+                // This can (and should only) affect subtitle streams.
+                if (buf->s.start < out_stream->next_pts)
+                {
+                    buf->s.start = out_stream->next_pts;
+                }
+                out_stream->next_pts = buf->s.start;
             }
 
-            out_stream->next_pts += buf->s.duration;
 
             if (buf->s.stop > 0)
             {