History

Merge commit 'b9dfee9fa259dfc885508179a359dccc9e7840bd'

* commit 'b9dfee9fa259dfc885508179a359dccc9e7840bd': vf_fade: switch to an AVOptions-based system. Conflicts: doc/filters.texi libavfilter/vf_fade.c

Michael Niedermayer committed 13 years ago

Commit 0c3d7062 parents d70b494 b9dfee93 files · +44 −41Browse files

Unified · Split

3 files
  1. doc/filters.texi +9 −12
  2. libavfilter/avfilter.c +1 −0
  3. libavfilter/vf_fade.c +34 −29
doc/filters.texi+9−12
@@ -3036,27 +3036,23 @@ edgedetect=low=0.1:high=0.4 · 3035 unmodified lines
30363036
30373037 Apply fade-in/out effect to input video.
30383038
3039−The filter accepts parameters as a list of @var{key}=@var{value}
3040−pairs, separated by ":". If the key of the first options is omitted,
3041−the arguments are interpreted according to the syntax
3042−@var{type}:@var{start_frame}:@var{nb_frames}.
3043−
3044−A description of the accepted parameters follows.
3039+This filter accepts the following options:
30453040
30463041 @table @option
30473042 @item type, t
3048−Specify if the effect type, can be either @code{in} for fade-in, or
3049−@code{out} for a fade-out effect. Default is @code{in}.
3043+The effect type -- can be either "in" for fade-in, or "out" for a fade-out
3044+effect.
3045+Default is @code{in}.
30503046
30513047 @item start_frame, s
30523048 Specify the number of the start frame for starting to apply the fade
30533049 effect. Default is 0.
30543050
30553051 @item nb_frames, n
3056−Specify the number of frames for which the fade effect has to last. At
3057−the end of the fade-in effect the output video will have the same
3058−intensity as the input video, at the end of the fade-out transition
3059−the output video will be completely black. Default is 25.
3052+The number of frames for which the fade effect has to last. At the end of the
3053+fade-in effect the output video will have the same intensity as the input video,
3054+at the end of the fade-out transition the output video will be completely black.
3055+Default is 25.
30603056
30613057 @item alpha
30623058 If set to 1, fade only alpha channel, if one exists on the input.
@@ -3081,6 +3077,7 @@ fade=t=in:s=0:n=30 · 18 unmodified lines
30813077 Fade out last 45 frames of a 200-frame video:
30823078 @example
30833079 fade=out:155:45
3080+fade=type=out:start_frame=155:nb_frames=45
30843081 @end example
30853082
30863083 @item
libavfilter/avfilter.c+1−0
@@ -664,6 +664,7 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 663 unmodified lines
664664 !strcmp(filter->filter->name, "delogo" ) ||
665665 !strcmp(filter->filter->name, "drawbox" ) ||
666666 !strcmp(filter->filter->name, "drawtext" ) ||
667+ !strcmp(filter->filter->name, "fade" ) ||
667668 !strcmp(filter->filter->name, "format") ||
668669 !strcmp(filter->filter->name, "noformat") ||
669670 !strcmp(filter->filter->name, "resample")
libavfilter/vf_fade.c+34−29
@@ -46,55 +46,40 @@ · 45 unmodified lines
4646 #define U 1
4747 #define V 2
4848
49+#define FADE_IN 0
50+#define FADE_OUT 1
51+
4952 typedef struct {
5053 const AVClass *class;
54+ int type;
5155 int factor, fade_per_frame;
52− unsigned int frame_index, start_frame, stop_frame, nb_frames;
56+ int start_frame, nb_frames;
57+ unsigned int frame_index, stop_frame;
5358 int hsub, vsub, bpp;
5459 unsigned int black_level, black_level_scaled;
5560 uint8_t is_packed_rgb;
5661 uint8_t rgba_map[4];
5762 int alpha;
5863
59− char *type;
6064 } FadeContext;
6165
62−#define OFFSET(x) offsetof(FadeContext, x)
63−#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
64−
65−static const AVOption fade_options[] = {
66− { "type", "set the fade direction", OFFSET(type), AV_OPT_TYPE_STRING, {.str = "in" }, CHAR_MIN, CHAR_MAX, FLAGS },
67− { "t", "set the fade direction", OFFSET(type), AV_OPT_TYPE_STRING, {.str = "in" }, CHAR_MIN, CHAR_MAX, FLAGS },
68− { "start_frame", "set expression of frame to start fading", OFFSET(start_frame), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, FLAGS },
69− { "s", "set expression of frame to start fading", OFFSET(start_frame), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, FLAGS },
70− { "nb_frames", "set expression for fade duration in frames", OFFSET(nb_frames), AV_OPT_TYPE_INT, {.i64 = 25 }, 0, INT_MAX, FLAGS },
71− { "n", "set expression for fade duration in frames", OFFSET(nb_frames), AV_OPT_TYPE_INT, {.i64 = 25 }, 0, INT_MAX, FLAGS },
72− { "alpha", "fade alpha if it is available on the input", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, FLAGS },
73− {NULL},
74−};
75−
76−AVFILTER_DEFINE_CLASS(fade);
77−
7866 static av_cold int init(AVFilterContext *ctx, const char *args)
7967 {
8068 FadeContext *fade = ctx->priv;
8169
8270 fade->fade_per_frame = (1 << 16) / fade->nb_frames;
83− if (!strcmp(fade->type, "in"))
71+ if (fade->type == FADE_IN) {
8472 fade->factor = 0;
85− else if (!strcmp(fade->type, "out")) {
73+ } else if (fade->type == FADE_OUT) {
8674 fade->fade_per_frame = -fade->fade_per_frame;
8775 fade->factor = (1 << 16);
88− } else {
89− av_log(ctx, AV_LOG_ERROR,
90− "Type argument must be 'in' or 'out' but '%s' was specified\n", fade->type);
91− return AVERROR(EINVAL);
9276 }
9377 fade->stop_frame = fade->start_frame + fade->nb_frames;
9478
9579 av_log(ctx, AV_LOG_VERBOSE,
9680 "type:%s start_frame:%d nb_frames:%d alpha:%d\n",
97− fade->type, fade->start_frame, fade->nb_frames, fade->alpha);
81+ fade->type == FADE_IN ? "in" : "out", fade->start_frame,
82+ fade->nb_frames, fade->alpha);
9883 return 0;
9984 }
10085
@@ -212,6 +197,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 111 unmodified lines
212197 return ff_filter_frame(inlink->dst->outputs[0], frame);
213198 }
214199
200+
201+#define OFFSET(x) offsetof(FadeContext, x)
202+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
203+
204+static const AVOption fade_options[] = {
205+ { "type", "'in' or 'out' for fade-in/fade-out", OFFSET(type), AV_OPT_TYPE_INT, { .i64 = FADE_IN }, FADE_IN, FADE_OUT, FLAGS, "type" },
206+ { "t", "'in' or 'out' for fade-in/fade-out", OFFSET(type), AV_OPT_TYPE_INT, { .i64 = FADE_IN }, FADE_IN, FADE_OUT, FLAGS, "type" },
207+ { "in", "fade-in", 0, AV_OPT_TYPE_CONST, { .i64 = FADE_IN }, .unit = "type" },
208+ { "out", "fade-out", 0, AV_OPT_TYPE_CONST, { .i64 = FADE_OUT }, .unit = "type" },
209+ { "start_frame", "Number of the first frame to which to apply the effect.",
210+ OFFSET(start_frame), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
211+ { "s", "Number of the first frame to which to apply the effect.",
212+ OFFSET(start_frame), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
213+ { "nb_frames", "Number of frames to which the effect should be applied.",
214+ OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, FLAGS },
215+ { "n", "Number of frames to which the effect should be applied.",
216+ OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, FLAGS },
217+ { "alpha", "fade alpha if it is available on the input", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, FLAGS },
218+ { NULL },
219+};
220+
221+AVFILTER_DEFINE_CLASS(fade);
222+
215223 static const AVFilterPad avfilter_vf_fade_inputs[] = {
216224 {
217225 .name = "default",
@@ -232,17 +240,14 @@ static const AVFilterPad avfilter_vf_fade_outputs[] = { · 14 unmodified lines
232240 { NULL }
233241 };
234242
235−static const char *const shorthand[] = { "type", "start_frame", "nb_frames", NULL };
236−
237243 AVFilter avfilter_vf_fade = {
238244 .name = "fade",
239245 .description = NULL_IF_CONFIG_SMALL("Fade in/out input video."),
240246 .init = init,
241247 .priv_size = sizeof(FadeContext),
248+ .priv_class = &fade_class,
242249 .query_formats = query_formats,
243250
244251 .inputs = avfilter_vf_fade_inputs,
245252 .outputs = avfilter_vf_fade_outputs,
246− .priv_class = &fade_class,
247− .shorthand = shorthand,
248253 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t