diff --git a/NEWS b/NEWS index 5eca473d4..f44fa5f23 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ver 0.21.2 (not yet released) * decoder - ffmpeg: require FFmpeg 3.1 or later + - ffmpeg: fix broken sound with certain codecs ver 0.21.1 (2018/11/04) * protocol diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx index 0abd04841..2b9b39b52 100644 --- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx +++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx @@ -556,28 +556,23 @@ FfmpegDecode(DecoderClient &client, InputStream &input, avcodec_parameters_to_context(codec_context, av_stream.codecpar); - const SampleFormat sample_format = - ffmpeg_sample_format(GetSampleFormat(codec_params)); - if (sample_format == SampleFormat::UNDEFINED) { - // (error message already done by ffmpeg_sample_format()) - return; - } - - const auto audio_format = CheckAudioFormat(codec_params.sample_rate, - sample_format, - codec_params.channels); - - /* the audio format must be read from AVCodecContext by now, - because avcodec_open() has been demonstrated to fill bogus - values into AVCodecContext.channels - a change that will be - reverted later by avcodec_decode_audio3() */ - const int open_result = avcodec_open2(codec_context, codec, nullptr); if (open_result < 0) { LogError(ffmpeg_domain, "Could not open codec"); return; } + const SampleFormat sample_format = + ffmpeg_sample_format(codec_context->sample_fmt); + if (sample_format == SampleFormat::UNDEFINED) { + // (error message already done by ffmpeg_sample_format()) + return; + } + + const auto audio_format = CheckAudioFormat(codec_context->sample_rate, + sample_format, + codec_context->channels); + const SignedSongTime total_time = av_stream.duration != (int64_t)AV_NOPTS_VALUE ? FromFfmpegTimeChecked(av_stream.duration, av_stream.time_base)