summaryrefslogtreecommitdiff
path: root/src/lib/ffmpeg_decoder.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-10-22 11:21:31 +0100
committerCarl Hetherington <cth@carlh.net>2012-10-22 11:21:31 +0100
commit4cb33e432c7070f59c3ee3fbeb0b5c8755bba3bd (patch)
treeb574347f4921b9b8edc9b1a64e6ae80c62b599cf /src/lib/ffmpeg_decoder.cc
parent1cc6986bdc5c35fd512257336f36bdb1b4142183 (diff)
Partial fix to sync according to pts.
Diffstat (limited to 'src/lib/ffmpeg_decoder.cc')
-rw-r--r--src/lib/ffmpeg_decoder.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index e52ea735f..d8a541be3 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -66,6 +66,7 @@ FFmpegDecoder::FFmpegDecoder (boost::shared_ptr<const FilmState> s, boost::share
, _audio_codec (0)
, _subtitle_codec_context (0)
, _subtitle_codec (0)
+ , _first_video_pts (-1)
{
setup_general ();
setup_video ();
@@ -221,6 +222,8 @@ FFmpegDecoder::do_pass ()
_packet.data = 0;
_packet.size = 0;
+ /* XXX: should we reset _packet.data and size after each *_decode_* call? */
+
int frame_finished;
while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
@@ -245,6 +248,9 @@ FFmpegDecoder::do_pass ()
int frame_finished;
if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) {
+ if (_first_video_pts == -1) {
+ _first_video_pts = _packet.pts;
+ }
process_video (_frame);
}
@@ -417,3 +423,15 @@ FFmpegDecoder::stream_name (AVStream* s) const
return n.str ();
}
+
+int
+FFmpegDecoder::audio_to_discard () const
+{
+ AVStream* v = _format_context->streams[_video_stream];
+ AVStream* a = _format_context->streams[_audio_stream];
+
+ assert (v->time_base.num == a->time_base.num);
+ assert (v->time_base.den == a->time_base.den);
+
+ return rint (av_q2d (v->time_base) * 1000 * (_first_video_pts - _first_audio_pts));
+}