From 04376fa02450dba51fd29a9e49423d57083041c9 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 25 Jan 2017 08:30:14 +0100 Subject: ad_lavc, vd_lavc: preserve codec_id/codec_type when setting params avcodec_parameters_to_context() overwrites codec_type and codec_id. But we already set these by passing the selected AVCodec to avcodec_alloc_context3(). It's entirely possible that at least codec_id is different when forcing codecs with --ad/--vd. It's probably better not to cause confusion by overwriting them. It might even trigger undefined behavior in libavcodec (how it behaves or whether codec_id is supposed to be strictly set is unknown, though). --- common/av_common.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'common') diff --git a/common/av_common.c b/common/av_common.c index e8a0e76ed2..aa1a1bfdf2 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -112,11 +112,19 @@ error: // Set avctx codec headers for decoding. Returns <0 on failure. int mp_set_avctx_codec_headers(AVCodecContext *avctx, struct mp_codec_params *c) { + enum AVMediaType codec_type = avctx->codec_type; + enum AVCodecID codec_id = avctx->codec_id; AVCodecParameters *avp = mp_codec_params_to_av(c); if (!avp) return -1; + int r = avcodec_parameters_to_context(avctx, avp) < 0 ? -1 : 0; avcodec_parameters_free(&avp); + + if (avctx->codec_type != AVMEDIA_TYPE_UNKNOWN) + avctx->codec_type = codec_type; + if (avctx->codec_id != AV_CODEC_ID_NONE) + avctx->codec_id = codec_id; return r; } -- cgit v1.2.3