[FFmpeg-devel] [PATCH 2/5] lavfi: add aformat filter

Stefano Sabatini stefano.sabatini-lala at poste.it
Sat Aug 13 19:00:07 CEST 2011


On date Friday 2011-08-12 12:51:03 +0300, Mina Nagy Zaki encoded:
> Updated after changes to ff_parse_* functions.
> 

> From 3f2eabe47103b90e09daf82821b9cc4efec6ce04 Mon Sep 17 00:00:00 2001
> From: Mina Nagy Zaki <mnzaki at gmail.com>
> Date: Thu, 14 Jul 2011 14:18:13 +0300
> Subject: [PATCH 02/16] lavfi: add aformat filter
> 
> ---
>  doc/filters.texi         |   21 ++++++++
>  libavfilter/Makefile     |    1 +
>  libavfilter/af_aformat.c |  114 ++++++++++++++++++++++++++++++++++++++++++++++
>  libavfilter/allfilters.c |    1 +
>  4 files changed, 137 insertions(+), 0 deletions(-)
>  create mode 100644 libavfilter/af_aformat.c
> 
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 33d6496..8dc1c15 100644
[...]
> --- /dev/null
> +++ b/libavfilter/af_aformat.c
> @@ -0,0 +1,114 @@
> +/*
> + * Copyright (c) 2011 Mina Nagy Zaki
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file

> + * format and noformat audio filters

no noformat

> + */
> +
> +#include "libavutil/audioconvert.h"
> +#include "avfilter.h"
> +#include "internal.h"
> +
> +typedef struct {
> +    AVFilterFormats *formats, *chlayouts, *packing;
> +} AFormatContext;
> +
> +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> +    AFormatContext * const aformat = ctx->priv;
> +    char *arg, *fmt_str;
> +    int64_t fmt;
> +    int ret;
> +
> +    arg = strsep(&args, ":");
> +    if (!arg) goto arg_fail;
> +    if (!strcmp(arg, "all")) {
> +        aformat->formats = avfilter_all_formats(AVMEDIA_TYPE_AUDIO);
> +    } else {
> +        while (fmt_str = strsep(&arg, ",")) {
> +            if ((ret = ff_parse_sample_format((int*)&fmt, fmt_str, ctx)) < 0)
> +                return ret;
> +            avfilter_add_format(&aformat->formats, fmt);
> +        }
> +    }
> +
> +    arg = strsep(&args, ":");
> +    if (!arg) goto arg_fail;
> +    if (!strcmp(arg, "all")) {
> +        aformat->chlayouts = avfilter_all_channel_layouts();
> +    } else {
> +        while (fmt_str = strsep(&arg, ",")) {
> +            if ((ret = ff_parse_channel_layout(&fmt, fmt_str, ctx)) < 0)
> +                return ret;
> +            avfilter_add_format(&aformat->chlayouts, fmt);
> +        }
> +    }
> +
> +    arg = strsep(&args, ":");
> +    if (!arg) goto arg_fail;
> +    if (!strcmp(arg, "all")) {
> +        aformat->packing = avfilter_all_packing_formats();
> +    } else {
> +        while (fmt_str = strsep(&arg, ",")) {
> +            if ((ret = ff_parse_packing_format((int*)&fmt, fmt_str, ctx)) < 0)
> +                return ret;
> +            avfilter_add_format(&aformat->packing, fmt);
> +        }
> +    }
> +
> +    return 0;
> +
> +arg_fail:

> +    av_log(ctx, AV_LOG_ERROR, "Please provide the required arguments "
> +                              "sample_fmts:channel_layouts:packing_fmts\n");

Note: my latest tendency is to avoid "please" in error messages,
computer programs are not supposed to tell the users what they should
do, they just suggest what's wrong if they are not so dumb.
Neither they can feel "pleased" when the user follow their advices.
;-).

Thus I prefer:
"Invalid syntax provided, the arguments must be in the form ...".

[...]

Fine otherwise, going to apply it soon.
-- 
FFmpeg = Fostering and Fierce Most Problematic Energized Geisha


More information about the ffmpeg-devel mailing list