[FFmpeg-devel] [PATCH] lavfi/fade: accept shorthand syntax

Stefano Sabatini stefasab at gmail.com
Fri Jan 18 19:02:19 CET 2013


TODO: bump micro
---
 doc/filters.texi      |   32 +++++++++++++-------------------
 libavfilter/vf_fade.c |   45 +++++++--------------------------------------
 2 files changed, 20 insertions(+), 57 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index be65350..9def1dc 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -2276,33 +2276,27 @@ edgedetect=low=0.1:high=0.4
 
 Apply fade-in/out effect to input video.
 
-It accepts the parameters:
- at var{type}:@var{start_frame}:@var{nb_frames}[:@var{options}]
-
- at var{type} specifies if the effect type, can be either "in" for
-fade-in, or "out" for a fade-out effect.
-
- at var{start_frame} specifies the number of the start frame for starting
-to apply the fade effect.
-
- at var{nb_frames} specifies the number of frames for which the fade
-effect has to last. At the end of the fade-in effect the output video
-will have the same intensity as the input video, at the end of the
-fade-out transition the output video will be completely black.
+The filter accepts parameters as a list of @var{key}=@var{value}
+pairs, separated by ":". If the key of the first options is omitted,
+the arguments are interpreted according to the syntax
+ at var{type}:@var{start_frame}:@var{nb_frames}.
 
- at var{options} is an optional sequence of @var{key}=@var{value} pairs,
-separated by ":". The description of the accepted options follows.
+A description of the accepted parameters follows.
 
 @table @option
-
 @item type, t
-See @var{type}.
+Specify if the effect type, can be either @code{in} for fade-in, or
+ at code{out} for a fade-out effect. Default is @code{in}.
 
 @item start_frame, s
-See @var{start_frame}.
+Specify the number of the start frame for starting to apply the fade
+effect. Default is 0.
 
 @item nb_frames, n
-See @var{nb_frames}.
+Specify the number of frames for which the fade effect has to last. At
+the end of the fade-in effect the output video will have the same
+intensity as the input video, at the end of the fade-out transition
+the output video will be completely black. Default is 25.
 
 @item alpha
 If set to 1, fade only alpha channel, if one exists on the input.
diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c
index 5be0ec1..38b936b 100644
--- a/libavfilter/vf_fade.c
+++ b/libavfilter/vf_fade.c
@@ -78,41 +78,14 @@ AVFILTER_DEFINE_CLASS(fade);
 static av_cold int init(AVFilterContext *ctx, const char *args)
 {
     FadeContext *fade = ctx->priv;
-    int ret = 0;
-    char *args1, *expr, *bufptr = NULL;
+    static const char *shorthand[] = { "type", "start_frame", "nb_frames", NULL };
+    int ret;
 
     fade->class = &fade_class;
     av_opt_set_defaults(fade);
 
-    if (!(args1 = av_strdup(args))) {
-        ret = AVERROR(ENOMEM);
-        goto end;
-    }
-
-    if (expr = av_strtok(args1, ":", &bufptr)) {
-        av_free(fade->type);
-        if (!(fade->type = av_strdup(expr))) {
-            ret = AVERROR(ENOMEM);
-            goto end;
-        }
-    }
-    if (expr = av_strtok(NULL, ":", &bufptr)) {
-        if ((ret = av_opt_set(fade, "start_frame", expr, 0)) < 0) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Invalid value '%s' for start_frame option\n", expr);
-            goto end;
-        }
-    }
-    if (expr = av_strtok(NULL, ":", &bufptr)) {
-        if ((ret = av_opt_set(fade, "nb_frames", expr, 0)) < 0) {
-            av_log(ctx, AV_LOG_ERROR,
-                   "Invalid value '%s' for nb_frames option\n", expr);
-            goto end;
-        }
-    }
-
-    if (bufptr && (ret = av_set_options_string(fade, bufptr, "=", ":")) < 0)
-        goto end;
+    if ((ret = av_opt_set_from_string(fade, args, shorthand, "=", ":")) < 0)
+        return ret;
 
     fade->fade_per_frame = (1 << 16) / fade->nb_frames;
     if (!strcmp(fade->type, "in"))
@@ -123,25 +96,21 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
     } else {
         av_log(ctx, AV_LOG_ERROR,
                "Type argument must be 'in' or 'out' but '%s' was specified\n", fade->type);
-        ret = AVERROR(EINVAL);
-        goto end;
+        return AVERROR(EINVAL);
     }
     fade->stop_frame = fade->start_frame + fade->nb_frames;
 
     av_log(ctx, AV_LOG_VERBOSE,
            "type:%s start_frame:%d nb_frames:%d alpha:%d\n",
            fade->type, fade->start_frame, fade->nb_frames, fade->alpha);
-
-end:
-    av_free(args1);
-    return ret;
+    return 0;
 }
 
 static av_cold void uninit(AVFilterContext *ctx)
 {
     FadeContext *fade = ctx->priv;
 
-    av_freep(&fade->type);
+    av_opt_free(fade);
 }
 
 static int query_formats(AVFilterContext *ctx)
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list