From d9fd19336dcb823a5f0199adf41b37eb8d177f4d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 7 Oct 2012 22:31:53 +0100 Subject: Pick up last few frames properly when decoding. --- src/lib/ffmpeg_decoder.cc | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 3471ffaab..1096bb253 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -161,11 +161,39 @@ 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; + + if (_opt->decode_video) { + 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) { - + int frame_finished; if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { process_video (_frame); -- cgit v1.2.3 From f29219ed06d27dcae5e18b8b9c52dcf24554f188 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 16:02:07 +0100 Subject: Remove unused variable. --- src/lib/ffmpeg_decoder.cc | 8 +++----- src/lib/options.h | 2 -- 2 files changed, 3 insertions(+), 7 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 1096bb253..3991323ce 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -172,10 +172,8 @@ FFmpegDecoder::do_pass () int frame_finished; - if (_opt->decode_video) { - while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { - process_video (_frame); - } + while (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { + process_video (_frame); } if (_audio_stream >= 0 && _opt->decode_audio) { @@ -192,7 +190,7 @@ FFmpegDecoder::do_pass () 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) { diff --git a/src/lib/options.h b/src/lib/options.h index 1156ece1d..45a1768c2 100644 --- a/src/lib/options.h +++ b/src/lib/options.h @@ -39,7 +39,6 @@ public: Options (std::string f, std::string e, std::string m) : padding (0) , apply_crop (true) - , decode_video (true) , decode_video_frequency (0) , decode_audio (true) , _frame_out_path (f) @@ -93,7 +92,6 @@ public: int padding; ///< number of pixels of padding (in terms of the output size) each side of the image bool apply_crop; ///< true to apply cropping int black_after; ///< first frame for which to output a black frame, rather than the actual video content, or 0 for none - bool decode_video; ///< true to decode video, otherwise false int decode_video_frequency; ///< skip frames so that this many are decoded in all (or 0) (for generating thumbnails) bool decode_audio; ///< true to decode audio, otherwise false -- cgit v1.2.3 From dc1b54d559dac0b722e8854d1f48c77a07507497 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 9 Oct 2012 17:13:09 +0100 Subject: Use r_frame_rate from AVStream if avg_frame_rate is not a number; fixes problems with some WMV files. --- src/lib/ffmpeg_decoder.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 3991323ce..767299ea6 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -225,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 -- cgit v1.2.3