[FFmpeg-devel] [PATCH] lavfi/volume: implement process_command() callback, with the volume command
Stefano Sabatini
stefasab at gmail.com
Mon Dec 23 18:26:55 CET 2013
Address trac ticket #2868.
TODO: bump micro
---
doc/filters.texi | 13 +++++++++++++
libavfilter/af_volume.c | 27 +++++++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/doc/filters.texi b/doc/filters.texi
index d29bedc..7d2d73a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1868,6 +1868,19 @@ Note that when @option{eval} is set to @samp{init} only the
@var{sample_rate} and @var{tb} variables are available, all other
variables will evaluate to NAN.
+ at subsection Commands
+
+This filter supports the following commands:
+ at table @option
+ at item volume
+
+Modify the volume expression.
+The command accepts the same syntax of the corresponding option.
+
+If the specified expression is not valid, it is kept at its current
+value.
+ at end table
+
@subsection Examples
@itemize
diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c
index 9bfd840..fbeb84c 100644
--- a/libavfilter/af_volume.c
+++ b/libavfilter/af_volume.c
@@ -298,6 +298,32 @@ static int config_output(AVFilterLink *outlink)
return 0;
}
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+ char *res, int res_len, int flags)
+{
+ VolumeContext *vol = ctx->priv;
+ int ret;
+
+ if (!strcmp(cmd, "volume"))
+ ret = set_expr(&vol->volume_pexpr, args, ctx);
+ else
+ ret = AVERROR(ENOSYS);
+
+ if (ret < 0)
+ return ret;
+
+ if (vol->eval_mode == EVAL_MODE_INIT) {
+ vol->volume = av_expr_eval(vol->volume_pexpr, vol->var_values, NULL);
+ if (isnan(vol->volume)) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid value NaN for volume, setting value to 0\n");
+ vol->volume = 0;
+ }
+ set_volume(ctx);
+ }
+
+ return 0;
+}
+
#define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d))
#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts))
#define TS2T(ts, tb) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)*av_q2d(tb))
@@ -429,4 +455,5 @@ AVFilter ff_af_volume = {
.inputs = avfilter_af_volume_inputs,
.outputs = avfilter_af_volume_outputs,
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
+ .process_command = process_command,
};
--
1.8.1.2
More information about the ffmpeg-devel
mailing list