[FFmpeg-devel] [PATCH] lavfi/volume: add dynamic expression evaluation

Clément Bœsch ubitux at gmail.com
Wed Feb 27 15:21:49 CET 2013


On Sat, Feb 23, 2013 at 01:00:40AM +0100, Stefano Sabatini wrote:
> TODO: update docs, bump micro
> ---
>  libavfilter/af_volume.c |  120 ++++++++++++++++++++++++++++++++++++-----------
>  libavfilter/af_volume.h |   20 ++++++++
>  2 files changed, 113 insertions(+), 27 deletions(-)
> 
> diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c
> index 5ffa1fe..87898c8 100644
> --- a/libavfilter/af_volume.c
> +++ b/libavfilter/af_volume.c
> @@ -29,6 +29,7 @@
>  #include "libavutil/eval.h"
>  #include "libavutil/float_dsp.h"
>  #include "libavutil/opt.h"
> +#include "libavutil/time.h"
>  #include "audio.h"
>  #include "avfilter.h"
>  #include "formats.h"
> @@ -39,13 +40,28 @@ static const char *precision_str[] = {
>      "fixed", "float", "double"
>  };
>  
> +static const char *const var_names[] = {
> +    "N",           ///< frame number (starting at zero)
> +    "NB_CONSUMED_SAMPLES", ///< number of samples consumed by the filter (only audio)
> +    "NB_SAMPLES",  ///< number of samples in the current frame (only audio)
> +    "POS",         ///< original position in the file of the frame
> +    "PTS",         ///< original pts in the file of the frame
> +    "RTC_STARTT",  ///< start wallclock (RTC) time in micro seconds
> +    "SAMPLE_RATE", ///< sample rate (only audio)
> +    "STARTPTS",    ///< PTS at start of stream
> +    "STARTT",      ///< time at start of stream
> +    "T",           ///< original time in the file of the frame
> +    "TB",          ///< timebase
> +    NULL
> +};
> +
>  #define OFFSET(x) offsetof(VolumeContext, x)
>  #define A AV_OPT_FLAG_AUDIO_PARAM
>  #define F AV_OPT_FLAG_FILTERING_PARAM
>  
>  static const AVOption volume_options[] = {
> -    { "volume", "set volume adjustment",
> -            OFFSET(volume), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 0, 0x7fffff, A|F },
> +    { "volume", "set volume adjustment expression",
> +            OFFSET(volume_expr), AV_OPT_TYPE_STRING, { .str = "1.0" }, .flags = A|F },
>      { "precision", "select mathematical precision",
>              OFFSET(precision), AV_OPT_TYPE_INT, { .i64 = PRECISION_FLOAT }, PRECISION_FIXED, PRECISION_DOUBLE, A|F, "precision" },
>          { "fixed",  "select 8-bit fixed-point",     0, AV_OPT_TYPE_CONST, { .i64 = PRECISION_FIXED  }, INT_MIN, INT_MAX, A|F, "precision" },
> @@ -68,21 +84,25 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
>      if ((ret = av_opt_set_from_string(vol, args, shorthand, "=", ":")) < 0)
>          return ret;
>  
> -    if (vol->precision == PRECISION_FIXED) {
> -        vol->volume_i = (int)(vol->volume * 256 + 0.5);
> -        vol->volume   = vol->volume_i / 256.0;
> -        av_log(ctx, AV_LOG_VERBOSE, "volume:(%d/256)(%f)(%1.2fdB) precision:fixed\n",
> -               vol->volume_i, vol->volume, 20.0*log(vol->volume)/M_LN10);
> -    } else {
> -        av_log(ctx, AV_LOG_VERBOSE, "volume:(%f)(%1.2fdB) precision:%s\n",
> -               vol->volume, 20.0*log(vol->volume)/M_LN10,
> -               precision_str[vol->precision]);
> +    if ((ret = av_expr_parse(&vol->volume_pexpr,vol->volume_expr,
> +                             var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) {
> +        av_log(ctx, AV_LOG_ERROR, "Error while parsing expression '%s'\n", vol->volume_expr);
> +        return ret;

Will that still support the "12dB" syntax?

Also, if it's a problem from a performance PoV (and the feature being
relatively marginal), would it make sense to instead add a "dyn_volume"
option?

[...]

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130227/1723ac26/attachment.asc>


More information about the ffmpeg-devel mailing list