Assumes that we are always seeking forward
| 6607 | |
| 6608 | // Assumes that we are always seeking forward |
| 6609 | static int ffmpeg_seek_ts( hb_stream_t *stream, int64_t ts ) |
| 6610 | { |
| 6611 | AVFormatContext *ic = stream->ffmpeg_ic; |
| 6612 | int64_t pos; |
| 6613 | int ret; |
| 6614 | |
| 6615 | // Find the initial chapter we have seeked into |
| 6616 | int count = hb_list_count(stream->title->list_chapter); |
| 6617 | if (count > 0) |
| 6618 | { |
| 6619 | int64_t sum_dur = 0; |
| 6620 | hb_chapter_t * chapter; |
| 6621 | int ii; |
| 6622 | for (ii = 0; ii < count; ii++) |
| 6623 | { |
| 6624 | chapter = hb_list_item( stream->title->list_chapter, ii ); |
| 6625 | if (sum_dur + chapter->duration > ts) |
| 6626 | { |
| 6627 | break; |
| 6628 | } |
| 6629 | sum_dur += chapter->duration; |
| 6630 | } |
| 6631 | stream->chapter = ii; |
| 6632 | stream->chapter_end = sum_dur; |
| 6633 | } |
| 6634 | else |
| 6635 | { |
| 6636 | stream->chapter = 0; |
| 6637 | stream->chapter_end = INT64_MAX; |
| 6638 | } |
| 6639 | |
| 6640 | pos = ts * AV_TIME_BASE / 90000 + ffmpeg_initial_timestamp( stream ); |
| 6641 | AVStream *st = stream->ffmpeg_ic->streams[stream->ffmpeg_video_id]; |
| 6642 | // timebase must be adjusted to match timebase of stream we are |
| 6643 | // using for seeking. |
| 6644 | pos = av_rescale(pos, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num); |
| 6645 | stream->need_keyframe = 1; |
| 6646 | // Seek to the nearest timestamp before that requested where |
| 6647 | // there is an I-frame |
| 6648 | ret = avformat_seek_file( ic, stream->ffmpeg_video_id, 0, pos, pos, 0); |
| 6649 | return ret; |
| 6650 | } |
no test coverage detected