From 5a7a576c41389aa7daebfc37d3d8b0763e96263b Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 10 Aug 2012 15:48:45 +0100 Subject: Untested fixes for files without audio. --- src/lib/ffmpeg_decoder.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/lib/ffmpeg_decoder.cc') diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index d2a10be1f..c12e6728d 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -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; } -- cgit v1.2.3