diff mbox series

[FFmpeg-devel,7/7] ffmpeg: make the ac option set the demuxer's ch_layout AVOption

Message ID 20220320200634.51420-1-jamrial@gmail.com
State New
Headers show
Series None | expand

Commit Message

James Almer March 20, 2022, 8:06 p.m. UTC
channels is deprecated on all supported raw demuxers.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 fftools/ffmpeg_opt.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Comments

Nicolas George March 20, 2022, 8:09 p.m. UTC | #1
James Almer (12022-03-20):
> channels is deprecated on all supported raw demuxers.
> 
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  fftools/ffmpeg_opt.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

I like this version much better.

Thanks.

> diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
> index 720a3cc46a..b3edbf9885 100644
> --- a/fftools/ffmpeg_opt.c
> +++ b/fftools/ffmpeg_opt.c
> @@ -1122,7 +1122,11 @@ static int open_input_file(OptionsContext *o, const char *filename)
>          if (file_iformat && (priv_class = file_iformat->priv_class) &&
>              av_opt_find(&priv_class, "channels", NULL, 0,
>                          AV_OPT_SEARCH_FAKE_OBJ)) {
> -            av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);

> +            AVBPrint bp;
> +            av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
> +            av_bprintf(&bp, "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
> +            av_dict_set(&o->g->format_opts, "ch_layout", bp.str, 0);
> +            av_bprint_finalize(&bp, NULL);

You do not need a BPrint for that, the size of the expansion of %d is
very limited, especially the values that can be relevant here.

>          }
>      }
>      if (o->nb_audio_ch_layouts) {

Regards,
diff mbox series

Patch

diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c
index 720a3cc46a..b3edbf9885 100644
--- a/fftools/ffmpeg_opt.c
+++ b/fftools/ffmpeg_opt.c
@@ -1122,7 +1122,11 @@  static int open_input_file(OptionsContext *o, const char *filename)
         if (file_iformat && (priv_class = file_iformat->priv_class) &&
             av_opt_find(&priv_class, "channels", NULL, 0,
                         AV_OPT_SEARCH_FAKE_OBJ)) {
-            av_dict_set_int(&o->g->format_opts, "channels", o->audio_channels[o->nb_audio_channels - 1].u.i, 0);
+            AVBPrint bp;
+            av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
+            av_bprintf(&bp, "%dC", o->audio_channels[o->nb_audio_channels - 1].u.i);
+            av_dict_set(&o->g->format_opts, "ch_layout", bp.str, 0);
+            av_bprint_finalize(&bp, NULL);
         }
     }
     if (o->nb_audio_ch_layouts) {