diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-12-18 21:13:10 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-12-18 21:13:10 +0000 |
| commit | 0330d9b2924767d9240c5a25e9ed4327eb0a73bd (patch) | |
| tree | c0041d4d64b6cc6b1dc57fd12e23b5ca552197c1 /src/lib/ffmpeg_decoder.cc | |
| parent | 880719c0bf2f2ce99ca44a5f5289fdd30962246a (diff) | |
Try to tidy up subtitle timing and seeks wrt source frames, DCP frames and rounding.
Diffstat (limited to 'src/lib/ffmpeg_decoder.cc')
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index f81f00b19..97d43c76c 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -543,24 +543,35 @@ FFmpegDecoder::filter_and_emit_video (AVFrame* frame) list<shared_ptr<Image> > images = graph->process (frame); - SourceFrame const sf = av_q2d (_format_context->streams[_video_stream]->time_base) - * av_frame_get_best_effort_timestamp(_frame) * frames_per_second(); + double const st = av_frame_get_best_effort_timestamp(_frame) * av_q2d (_format_context->streams[_video_stream]->time_base); for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) { - emit_video (*i, sf); + emit_video (*i, st); } } bool -FFmpegDecoder::seek (SourceFrame f) +FFmpegDecoder::seek (double p) { - int64_t const vt = static_cast<int64_t>(f) / (av_q2d (_format_context->streams[_video_stream]->time_base) * frames_per_second()); + return do_seek (p, false); +} - /* This AVSEEK_FLAG_BACKWARD is a bit of a hack; without it, if we ask for a seek to the same place as last time +bool +FFmpegDecoder::seek_to_last () +{ + /* This AVSEEK_FLAG_BACKWARD in do_seek is a bit of a hack; without it, if we ask for a seek to the same place as last time (used when we change decoder parameters and want to re-fetch the frame) we end up going forwards rather than staying in the same place. */ - int const r = av_seek_frame (_format_context, _video_stream, vt, (f == last_source_frame() ? AVSEEK_FLAG_BACKWARD : 0)); + return do_seek (last_source_time(), true); +} + +bool +FFmpegDecoder::do_seek (double p, bool backwards) +{ + int64_t const vt = p / av_q2d (_format_context->streams[_video_stream]->time_base); + + int const r = av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0); avcodec_flush_buffers (_video_codec_context); if (_subtitle_codec_context) { |
