[FFmpeg-devel] [PATCH] ffmpeg: guess channel layout from number of channels if needed

Stefano Sabatini stefano.sabatini-lala at poste.it
Sat Aug 20 20:08:52 CEST 2011


On date Friday 2011-08-19 02:22:36 +0300, Mina Nagy Zaki encoded:
> Guess channel layout from number of channels instead of setting the encoder's
> channel_layout to 0
> 
> This breaks a number of acodec-pcm regtests due to wav headers now containing a
> channel layout mask instead of 0x0
> ---
>  ffmpeg.c |    8 +++++---
>  1 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/ffmpeg.c b/ffmpeg.c
> index 2c66076..e5ee33b 100644
> --- a/ffmpeg.c
> +++ b/ffmpeg.c
> @@ -2313,10 +2313,12 @@ static int transcode(AVFormatContext **output_files,
>                  choose_sample_fmt(ost->st, ost->enc);
>                  if (!codec->channels) {
>                      codec->channels = icodec->channels;
> -                    codec->channel_layout = icodec->channel_layout;
> +                    if (icodec->channel_layout)
> +                        codec->channel_layout = icodec->channel_layout;
> +                    else
> +                        codec->channel_layout =
> +                            avcodec_guess_channel_layout(codec->channels, 0, NULL);

nit:

codec->channel_layout = icodec->channel_layout ? icodec->channel_layout :
                        avcodec_guess_channel_layout(codec->channels, 0, NULL);

simpler to read

But this logic looks busted.

For example if you set the output channel layout but not the number of
channels, it will override the specified chlayout value by setting it
to the input channel layout, which is not the expected behavior.

In that case the output number of channels should be guessed from the
layout, and should not derived from the input chlayout.

So I'd keep channels_nb/channel layout setting logic separated.

The tricky part is that chlayout and number of channels are
dependent on each other (so a consistency check should be added).

>                  }
> -                if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels)
> -                    codec->channel_layout = 0;
>                  ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1;
>                  icodec->request_channels = codec->channels;
>                  ist->decoding_needed = 1;

Which regtests are changed?

For fixing regtests, you simply edit the files in test/ref/ with the
resulting new output files.
-- 
FFmpeg = Fundamentalist and Free Murdering Peaceless Extensive Gorilla


More information about the ffmpeg-devel mailing list