On Mon,  9 Apr 2012 13:46:18 -0400, Justin Ruggles <[email protected]> 
wrote:
> This allows the user to use channel layout names instead of having to use the
> channel mask values.
> ---
>  avconv.c |   34 ++++++++++++++++++++++++++++++++++
>  1 files changed, 34 insertions(+), 0 deletions(-)
> 
> diff --git a/avconv.c b/avconv.c
> index 2dce66f..9a914a5 100644
> --- a/avconv.c
> +++ b/avconv.c
> @@ -4377,6 +4377,39 @@ static void parse_cpuflags(int argc, char **argv, 
> const OptionDef *options)
>          opt_cpuflags("cpuflags", argv[idx + 1]);
>  }
>  
> +static int opt_channel_layout(OptionsContext *o, const char *opt, const char 
> *arg)
> +{
> +    char layout_str[32];
> +    char *stream_str;
> +    char *ac_str;
> +    int channels, ac_str_size;
> +    uint64_t layout;
> +
> +    layout = av_get_channel_layout(arg);
> +    if (!layout) {
> +        av_log(NULL, AV_LOG_ERROR, "Unknown channel layout: %s\n", arg);
> +        return AVERROR(EINVAL);
> +    }
> +    snprintf(layout_str, sizeof(layout_str), "%"PRIu64, layout);
> +    opt_default(opt, layout_str);
> +
> +    /* set 'ac' option based on channel layout */
> +    channels = av_get_channel_layout_nb_channels(layout);
> +    snprintf(layout_str, sizeof(layout_str), "%d", channels);
> +    stream_str = strchr(opt, ':');
> +    ac_str_size = 3 + (stream_str ? strlen(stream_str) : 0);
> +    ac_str = av_mallocz(ac_str_size);
> +    if (!ac_str)
> +        return AVERROR(ENOMEM);
> +    av_strlcpy(ac_str, "ac", 3);
> +    if (stream_str)
> +        av_strlcat(ac_str, stream_str, ac_str_size);
> +    parse_option(o, ac_str, layout_str, options);
> +    av_free(ac_str);
> +
> +    return 0;
> +}
> +

You should forward the errors from opt_default and parse_option.

Otherwise looks fine.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to