From e590bf7c94592b4351e57db5f66fedb7e7e8e3af Mon Sep 17 00:00:00 2001 From: John Stebbins Date: Fri, 28 Apr 2017 10:29:54 -0700 Subject: [PATCH] stream: fix chapter marker durations libav isn't guaranteed to set AVChapter.end. So don't use it. Use AVChapter.start instead. --- libhb/stream.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/libhb/stream.c b/libhb/stream.c index 76d7fe4f3..98b52fb72 100644 --- a/libhb/stream.c +++ b/libhb/stream.c @@ -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; -- 2.40.0