Untested fixes for files without audio.
authorCarl Hetherington <cth@carlh.net>
Fri, 10 Aug 2012 14:48:45 +0000 (15:48 +0100)
committerCarl Hetherington <cth@carlh.net>
Fri, 10 Aug 2012 14:48:45 +0000 (15:48 +0100)
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h

index d2a10be1f28ecd0fab35ea2514e43c2269e7e41a..c12e6728df299d310607bd46a17ecc5223e8fec6 100644 (file)
@@ -107,9 +107,6 @@ FFmpegDecoder::setup_general ()
        if (_video_stream < 0) {
                throw DecodeError ("could not find video stream");
        }
-       if (_audio_stream < 0) {
-               throw DecodeError ("could not find audio stream");
-       }
 
        _frame = avcodec_alloc_frame ();
        if (_frame == 0) {
@@ -135,6 +132,10 @@ FFmpegDecoder::setup_video ()
 void
 FFmpegDecoder::setup_audio ()
 {
+       if (_audio_stream < 0) {
+               return;
+       }
+       
        _audio_codec_context = _format_context->streams[_audio_stream]->codec;
        _audio_codec = avcodec_find_decoder (_audio_codec_context->codec_id);
 
@@ -162,7 +163,7 @@ FFmpegDecoder::do_pass ()
                        process_video (_frame);
                }
 
-       } else if (_packet.stream_index == _audio_stream && _opt->decode_audio) {
+       } else if (_audio_stream >= 0 && _packet.stream_index == _audio_stream && _opt->decode_audio) {
                
                avcodec_get_frame_defaults (_frame);
                
@@ -216,12 +217,20 @@ FFmpegDecoder::audio_sample_rate () const
 AVSampleFormat
 FFmpegDecoder::audio_sample_format () const
 {
+       if (_audio_codec_context == 0) {
+               return (AVSampleFormat) 0;
+       }
+       
        return _audio_codec_context->sample_fmt;
 }
 
 int64_t
 FFmpegDecoder::audio_channel_layout () const
 {
+       if (_audio_codec_context == 0) {
+               return 0;
+       }
+       
        return _audio_codec_context->channel_layout;
 }
 
index 8e7d685805264213925102da1fd27968d9c0a5b8..4e5445f673acfcd53ebb573f1cf23cf12c644ab4 100644 (file)
@@ -79,13 +79,13 @@ private:
 
        AVFormatContext* _format_context;
        int _video_stream;
-       int _audio_stream;
+       int _audio_stream; ///< may be < 0 if there is no audio
        AVFrame* _frame;
        
        AVCodecContext* _video_codec_context;
        AVCodec* _video_codec;
-       AVCodecContext* _audio_codec_context;
-       AVCodec* _audio_codec;
+       AVCodecContext* _audio_codec_context; ///< may be 0 if there is no audio
+       AVCodec* _audio_codec;                ///< may be 0 if there is no audio
 
        AVPacket _packet;
 };