summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libhb/stream.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/libhb/stream.c b/libhb/stream.c
index 0c89b8f59..261d50f84 100644
--- a/libhb/stream.c
+++ b/libhb/stream.c
@@ -1763,18 +1763,26 @@ int hb_stream_seek_chapter( hb_stream_t * stream, int chapter_num )
stream->chapter = chapter_num - 1;
stream->chapter_end = sum_dur;
- int64_t pos = ( ( ( sum_dur - chapter->duration ) * AV_TIME_BASE ) / 90000 ) + ffmpeg_initial_timestamp( stream );
+ if (chapter != NULL && chapter_num > 1)
+ {
+ int64_t pos = (((sum_dur - chapter->duration) * AV_TIME_BASE) / 90000) +
+ ffmpeg_initial_timestamp(stream);
- hb_deep_log( 2, "Seeking to chapter %d: starts %"PRId64", ends %"PRId64", AV pos %"PRId64,
- chapter_num, sum_dur - chapter->duration, sum_dur, pos);
+ if (pos > 0)
+ {
+ hb_deep_log(2,
+ "Seeking to chapter %d: starts %"PRId64", ends %"PRId64
+ ", AV pos %"PRId64,
+ chapter_num, sum_dur - chapter->duration, sum_dur, pos);
- if ( chapter_num > 1 && pos > 0 )
- {
- AVStream *st = stream->ffmpeg_ic->streams[stream->ffmpeg_video_id];
- // timebase must be adjusted to match timebase of stream we are
- // using for seeking.
- pos = av_rescale(pos, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num);
- avformat_seek_file( stream->ffmpeg_ic, stream->ffmpeg_video_id, 0, pos, pos, AVSEEK_FLAG_BACKWARD);
+ AVStream *st = stream->ffmpeg_ic->streams[stream->ffmpeg_video_id];
+ // timebase must be adjusted to match timebase of stream we are
+ // using for seeking.
+ pos = av_rescale(pos, st->time_base.den,
+ AV_TIME_BASE * (int64_t)st->time_base.num);
+ avformat_seek_file(stream->ffmpeg_ic, stream->ffmpeg_video_id, 0,
+ pos, pos, AVSEEK_FLAG_BACKWARD);
+ }
}
return 1;
}