From df52b97f307605aad15ab5f01c8fdcf93afc9d15 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Jul 2013 22:16:46 +0100 Subject: Various fixes; simplification of FilmViewer; make image appear on first load of content. --- src/lib/ffmpeg_decoder.cc | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index bf0949130..3b7d727b8 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -67,6 +67,7 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr f, shared_ptrvideo_frame_rate() / av_q2d (_format_context->streams[_video_stream]->time_base); + 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); - _video_position = frame; avcodec_flush_buffers (video_codec_context()); if (_subtitle_codec_context) { avcodec_flush_buffers (_subtitle_codec_context); } + _just_sought = true; + if (accurate) { while (1) { int r = av_read_frame (_format_context, &_packet); @@ -420,6 +422,15 @@ FFmpegDecoder::decode_video_packet () if (bet != AV_NOPTS_VALUE) { double const pts = bet * av_q2d (_format_context->streams[_video_stream]->time_base) - _pts_offset; + + if (_just_sought) { + /* 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 (); + _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; @@ -445,6 +456,7 @@ FFmpegDecoder::decode_video_packet () /* This PTS is within a frame of being right; emit this (otherwise it will be dropped) */ video (image, false, _video_position); } + } else { shared_ptr film = _film.lock (); assert (film); -- cgit v1.2.3