diff options
Diffstat (limited to 'src/lib/ffmpeg_decoder.cc')
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 3b7d727b8..bcd1e738a 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -281,26 +281,11 @@ FFmpegDecoder::bytes_per_audio_sample () const } void -FFmpegDecoder::seek (VideoContent::Frame frame) +FFmpegDecoder::seek (VideoContent::Frame frame, bool accurate) { - do_seek (frame, false, false); -} - -void -FFmpegDecoder::seek_back () -{ - if (_video_position == 0) { - return; - } - - do_seek (_video_position - 1, true, true); -} - -void -FFmpegDecoder::do_seek (VideoContent::Frame frame, bool backwards, bool accurate) -{ - int64_t const vt = frame / (_ffmpeg_content->video_frame_rate() * av_q2d (_format_context->streams[_video_stream]->time_base)); - av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0); + double const time_base = av_q2d (_format_context->streams[_video_stream]->time_base); + int64_t const vt = frame / (_ffmpeg_content->video_frame_rate() * time_base); + av_seek_frame (_format_context, _video_stream, vt, AVSEEK_FLAG_BACKWARD); avcodec_flush_buffers (video_codec_context()); if (_subtitle_codec_context) { @@ -323,9 +308,11 @@ FFmpegDecoder::do_seek (VideoContent::Frame frame, bool backwards, bool accurate int const r = avcodec_decode_video2 (video_codec_context(), _frame, &finished, &_packet); if (r >= 0 && finished) { int64_t const bet = av_frame_get_best_effort_timestamp (_frame); - if (bet > vt) { - _video_position = (bet * av_q2d (_format_context->streams[_video_stream]->time_base) + _pts_offset) - * _ffmpeg_content->video_frame_rate(); + if (bet >= vt) { + _video_position = rint ( + (bet * time_base + _pts_offset) * _ffmpeg_content->video_frame_rate() + ); + av_free_packet (&_packet); break; } } @@ -427,10 +414,10 @@ FFmpegDecoder::decode_video_packet () /* We just did a seek, so disable any attempts to correct for where we are / should be. */ - _video_position = pts * _ffmpeg_content->video_frame_rate (); + _video_position = rint (pts * _ffmpeg_content->video_frame_rate ()); _just_sought = false; } - + double const next = _video_position / _ffmpeg_content->video_frame_rate(); double const one_frame = 1 / _ffmpeg_content->video_frame_rate (); double delta = pts - next; |
