[FFmpeg-devel] [PATCH 1/5] fftools/ffmpeg_demux: also set -ch_layout avcodec option for -ch_layout CLI param

Anton Khirnov anton at khirnov.net
Mon May 27 10:51:49 EEST 2024


Quoting Marton Balint (2024-05-18 18:11:12)
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index cba63dab5f..6e23079ceb 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -1524,6 +1524,33 @@ static Demuxer *demux_alloc(void)
>      return d;
>  }
>  
> +static int set_input_ch_layout_opts(const OptionsContext *o)
> +{
> +    /* "ch_layout" is only a valid format option for some formats, but we set
> +     * it anyway, because it is also a codec option and we don't report
> +     * unconsumed format options if they are codec options as well. */
> +    for (int i = 0; i < o->audio_channels.nb_opt; i++) {
> +        char val[32];
> +        char *spec = o->audio_channels.opt[i].specifier;
> +        char *key = av_asprintf("ch_layout%s%s", spec[0] ? ":" : "", spec);
> +        if (!key)
> +            return AVERROR(ENOMEM);
> +        snprintf(val, sizeof(val), "%dC", o->audio_channels.opt[i].u.i);
> +        av_dict_set(&o->g->format_opts, key, val, 0);
> +        av_dict_set(&o->g->codec_opts,  key, val, AV_DICT_DONT_STRDUP_KEY);

I don't like modifying OptionsContext in its consumers (it's const for a
reason), and it's probably not even necessary - if the semantics of the
option is "override demuxer-reported channel layout", then you can just
override the demuxer-reported channel layout (similarly to how
guess_input_channel_layout() does it) and it will be communicated to the
decoder automagically.

-- 
Anton Khirnov


More information about the ffmpeg-devel mailing list