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) {
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);
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);
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;
}
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;
};