diff options
author | wm4 <wm4@nowhere> | 2017-01-25 08:30:14 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2017-01-25 08:30:14 +0100 |
commit | 04376fa02450dba51fd29a9e49423d57083041c9 (patch) | |
tree | 371fa6dd47a4d42f6139e845ad1c15e02298fd90 /common/av_common.c | |
parent | 801fa486b0b43badd05cbab64d796b3eb5a2d129 (diff) | |
download | mpv-04376fa02450dba51fd29a9e49423d57083041c9.tar.bz2 mpv-04376fa02450dba51fd29a9e49423d57083041c9.tar.xz |
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).
Diffstat (limited to 'common/av_common.c')
-rw-r--r-- | common/av_common.c | 8 |
1 files changed, 8 insertions, 0 deletions
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; } |