From 3eb8f9a1de70f03c4ef2b1c6ec0cecb81f84c103 Mon Sep 17 00:00:00 2001 From: nanahi <130121847+na-na-hi@users.noreply.github.com> Date: Fri, 20 Feb 2026 19:18:10 -0500 Subject: [PATCH] demux_lavf: get codec info from AVCodecParameters This allows displaying codec info for all tracks without selecting the track. --- common/av_common.c | 16 ++++++++++++++++ common/av_common.h | 1 + demux/demux_lavf.c | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/common/av_common.c b/common/av_common.c index af72b54e98..805ea4bed2 100644 --- a/common/av_common.c +++ b/common/av_common.c @@ -421,3 +421,19 @@ void mp_codec_info_from_av(const AVCodecContext *avctx, struct mp_codec_params * c->decoder = avctx->codec->name; c->decoder_desc = avctx->codec->long_name; } + +void mp_codec_info_from_avcodecpar(const AVCodecParameters *avcodecpar, struct mp_codec_params *c) +{ + const AVCodec *codec = avcodec_find_decoder(avcodecpar->codec_id); + const AVCodecDescriptor *desc = avcodec_descriptor_get(avcodecpar->codec_id); + c->codec = mp_codec_from_av_codec_id(avcodecpar->codec_id); + if (desc) + c->codec_desc = desc->long_name; + if (codec) { + c->decoder = codec->name; + c->decoder_desc = codec->long_name; + c->codec_profile = av_get_profile_name(codec, avcodecpar->profile); + } + if (!c->codec_profile) + c->codec_profile = avcodec_profile_name(avcodecpar->codec_id, avcodecpar->profile); +} diff --git a/common/av_common.h b/common/av_common.h index b019aa88e1..1947f68cd1 100644 --- a/common/av_common.h +++ b/common/av_common.h @@ -52,5 +52,6 @@ int mp_set_avopts(struct mp_log *log, void *avobj, char **kv); int mp_set_avopts_pos(struct mp_log *log, void *avobj, void *posargs, char **kv); void mp_free_av_packet(AVPacket **pkt); void mp_codec_info_from_av(const AVCodecContext *avctx, struct mp_codec_params *c); +void mp_codec_info_from_avcodecpar(const AVCodecParameters *avcodecpar, struct mp_codec_params *c); #endif diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index d1be000dd5..976e2516ea 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -820,7 +820,7 @@ static void handle_new_stream(demuxer_t *demuxer, int i) if (sh) { sh->ff_index = st->index; - sh->codec->codec = mp_codec_from_av_codec_id(codec->codec_id); + mp_codec_info_from_avcodecpar(codec, sh->codec); sh->codec->codec_tag = codec->codec_tag; sh->codec->lav_codecpar = avcodec_parameters_alloc(); if (sh->codec->lav_codecpar)