mirror of
https://github.com/mpv-player/mpv
synced 2025-01-28 02:23:06 +00:00
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).
This commit is contained in:
parent
801fa486b0
commit
04376fa024
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user