diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-10-10 10:02:20 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-10-10 10:02:20 +0100 |
| commit | cb33319a820b17a05cfb2ef78ba1799f4d0c54b9 (patch) | |
| tree | 7529501950b16db912a527d269ed83e39a37f7d6 /src/lib/ffmpeg_decoder.cc | |
| parent | 3781be4da4601176d7bb954f9cc65621d75e7344 (diff) | |
| parent | a097506d4867fec47406283caa5b262a21791585 (diff) | |
Merge branch 'master' of /home/carl/git/dvdomatic
Diffstat (limited to 'src/lib/ffmpeg_decoder.cc')
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 3471ffaab..767299ea6 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -161,11 +161,37 @@ FFmpegDecoder::do_pass () { int r = av_read_frame (_format_context, &_packet); if (r < 0) { + if (r != AVERROR_EOF) { + throw DecodeError ("error on av_read_frame"); + } + + /* Get any remaining frames */ + + _packet.data = 0; + _packet.size = 0; + + int frame_finished; + + while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { + process_video (_frame); + } + + if (_audio_stream >= 0 && _opt->decode_audio) { + while (avcodec_decode_audio4 (_audio_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { + int const data_size = av_samples_get_buffer_size ( + 0, _audio_codec_context->channels, _frame->nb_samples, audio_sample_format (), 1 + ); + + assert (_audio_codec_context->channels == _fs->audio_channels); + process_audio (_frame->data[0], data_size); + } + } + return true; } - if (_packet.stream_index == _video_stream && _opt->decode_video) { - + if (_packet.stream_index == _video_stream) { + int frame_finished; if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { process_video (_frame); @@ -199,7 +225,13 @@ FFmpegDecoder::length_in_frames () const float FFmpegDecoder::frames_per_second () const { - return av_q2d (_format_context->streams[_video_stream]->avg_frame_rate); + AVStream* s = _format_context->streams[_video_stream]; + + if (s->avg_frame_rate.num && s->avg_frame_rate.den) { + return av_q2d (s->avg_frame_rate); + } + + return av_q2d (s->r_frame_rate); } int |
