]> granicus.if.org Git - handbrake/commitdiff
stream: fix chapter marker durations
authorJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 28 Apr 2017 17:29:54 +0000 (10:29 -0700)
committerJohn Stebbins <jstebbins.hb@gmail.com>
Fri, 28 Apr 2017 17:29:54 +0000 (10:29 -0700)
libav isn't guaranteed to set AVChapter.end.  So don't use it.  Use
AVChapter.start instead.

libhb/stream.c

index 76d7fe4f3563deece922cb3afce2407898d8db26..98b52fb728b28528f51e5b7bee7ec4d5ee9e6ce3 100644 (file)
@@ -5586,11 +5586,26 @@ static hb_title_t *ffmpeg_title_scan( hb_stream_t *stream, hb_title_t *title )
         for( i = 0; i < ic->nb_chapters; i++ )
             if( ( m = ic->chapters[i] ) != NULL )
             {
-                AVDictionaryEntry *tag;
-                hb_chapter_t * chapter;
-                chapter = calloc( sizeof( hb_chapter_t ), 1 );
-                chapter->index    = i+1;
-                chapter->duration = ( m->end / ( (double) m->time_base.num * m->time_base.den ) ) * 90000  - duration_sum;
+                AVDictionaryEntry * tag;
+                hb_chapter_t      * chapter;
+                int64_t             end;
+
+                chapter = calloc(sizeof(hb_chapter_t), 1);
+                chapter->index    = i + 1;
+
+                /* AVChapter.end is not guaranteed to be set.
+                 * Calculate chapter durations based on AVChapter.start.
+                 */
+                if (i + 1 < ic->nb_chapters)
+                {
+                    end = ic->chapters[i + 1]->start * 90000 *
+                          m->time_base.num / m->time_base.den;
+                }
+                else
+                {
+                    end = ic->duration * 90000 / AV_TIME_BASE;
+                }
+                chapter->duration = end - duration_sum;
                 duration_sum     += chapter->duration;
 
                 int seconds      = ( chapter->duration + 45000 ) / 90000;