History

vf_fade: switch to an AVOptions-based system.

Anton Khirnov committed 13 years ago

Commit b9dfee91 parent 8ec464c2 files · +53 −34Browse files

Unified · Split

2 files
  1. doc/filters.texi +18 −14
  2. libavfilter/vf_fade.c +35 −20
doc/filters.texi+18−14
@@ -1000,33 +1000,37 @@ For more information about libfreetype, check: · 999 unmodified lines
10001000
10011001 Apply fade-in/out effect to input video.
10021002
1003−It accepts the parameters:
1004−@var{type}:@var{start_frame}:@var{nb_frames}
1003+This filter accepts the following options:
1004+
1005+@table @option
10051006
1006−@var{type} specifies if the effect type, can be either "in" for
1007−fade-in, or "out" for a fade-out effect.
1007+@item type
1008+The effect type -- can be either "in" for fade-in, or "out" for a fade-out
1009+effect.
1010+
1011+@item start_frame
1012+The number of the start frame for starting to apply the fade effect.
10081013
1009−@var{start_frame} specifies the number of the start frame for starting
1010−to apply the fade effect.
1014+@item nb_frames
1015+The number of frames for which the fade effect has to last. At the end of the
1016+fade-in effect the output video will have the same intensity as the input video,
1017+at the end of the fade-out transition the output video will be completely black.
10111018
1012−@var{nb_frames} specifies the number of frames for which the fade
1013−effect has to last. At the end of the fade-in effect the output video
1014−will have the same intensity as the input video, at the end of the
1015−fade-out transition the output video will be completely black.
1019+@end table
10161020
10171021 A few usage examples follow, usable too as test scenarios.
10181022 @example
10191023 # fade in first 30 frames of video
1020−fade=in:0:30
1024+fade=type=in:nb_frames=30
10211025
10221026 # fade out last 45 frames of a 200-frame video
1023−fade=out:155:45
1027+fade=type=out:start_frame=155:nb_frames=45
10241028
10251029 # fade in first 25 frames and fade out last 25 frames of a 1000-frame video
1026−fade=in:0:25, fade=out:975:25
1030+fade=type=in:start_frame=0:nb_frames=25, fade=type=out:start_frame=975:nb_frames=25
10271031
10281032 # make first 5 frames black, then fade in from frame 5-24
1029−fade=in:5:20
1033+fade=type=in:start_frame=5:nb_frames=20
10301034 @end example
10311035
10321036 @section fieldorder
libavfilter/vf_fade.c+35−20
@@ -26,48 +26,42 @@ · 25 unmodified lines
2626 */
2727
2828 #include "libavutil/common.h"
29+#include "libavutil/opt.h"
2930 #include "libavutil/pixdesc.h"
3031 #include "avfilter.h"
3132 #include "formats.h"
3233 #include "internal.h"
3334 #include "video.h"
3435
36+#define FADE_IN 0
37+#define FADE_OUT 1
38+
3539 typedef struct {
40+ const AVClass *class;
41+ int type;
3642 int factor, fade_per_frame;
37− unsigned int frame_index, start_frame, stop_frame;
43+ int start_frame, nb_frames;
44+ unsigned int frame_index, stop_frame;
3845 int hsub, vsub, bpp;
3946 } FadeContext;
4047
4148 static av_cold int init(AVFilterContext *ctx, const char *args)
4249 {
4350 FadeContext *fade = ctx->priv;
44− unsigned int nb_frames;
45− char in_out[4];
46−
47− if (!args ||
48− sscanf(args, " %3[^:]:%u:%u", in_out, &fade->start_frame, &nb_frames) != 3) {
49− av_log(ctx, AV_LOG_ERROR,
50− "Expected 3 arguments '(in|out):#:#':'%s'\n", args);
51− return AVERROR(EINVAL);
52− }
5351
54− nb_frames = nb_frames ? nb_frames : 1;
55− fade->fade_per_frame = (1 << 16) / nb_frames;
56− if (!strcmp(in_out, "in"))
52+ fade->fade_per_frame = (1 << 16) / fade->nb_frames;
53+ if (fade->type == FADE_IN) {
5754 fade->factor = 0;
58− else if (!strcmp(in_out, "out")) {
55+ } else if (fade->type == FADE_OUT) {
5956 fade->fade_per_frame = -fade->fade_per_frame;
6057 fade->factor = (1 << 16);
61− } else {
62− av_log(ctx, AV_LOG_ERROR,
63− "first argument must be 'in' or 'out':'%s'\n", in_out);
64− return AVERROR(EINVAL);
6558 }
66− fade->stop_frame = fade->start_frame + nb_frames;
59+ fade->stop_frame = fade->start_frame + fade->nb_frames;
6760
6861 av_log(ctx, AV_LOG_VERBOSE,
6962 "type:%s start_frame:%d nb_frames:%d\n",
70− in_out, fade->start_frame, nb_frames);
63+ fade->type == FADE_IN ? "in" : "out", fade->start_frame,
64+ fade->nb_frames);
7165 return 0;
7266 }
7367
@@ -143,6 +137,26 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 69 unmodified lines
143137 return ff_filter_frame(inlink->dst->outputs[0], frame);
144138 }
145139
140+#define OFFSET(x) offsetof(FadeContext, x)
141+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
142+static const AVOption options[] = {
143+ { "type", "'in' or 'out' for fade-in/fade-out", OFFSET(type), AV_OPT_TYPE_INT, { .i64 = FADE_IN }, FADE_IN, FADE_OUT, FLAGS, "type" },
144+ { "in", "fade-in", 0, AV_OPT_TYPE_CONST, { .i64 = FADE_IN }, .unit = "type" },
145+ { "out", "fade-out", 0, AV_OPT_TYPE_CONST, { .i64 = FADE_OUT }, .unit = "type" },
146+ { "start_frame", "Number of the first frame to which to apply the effect.",
147+ OFFSET(start_frame), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
148+ { "nb_frames", "Number of frames to which the effect should be applied.",
149+ OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, FLAGS },
150+ { NULL },
151+};
152+
153+static const AVClass fade_class = {
154+ .class_name = "fade",
155+ .item_name = av_default_item_name,
156+ .option = options,
157+ .version = LIBAVUTIL_VERSION_INT,
158+};
159+
146160 static const AVFilterPad avfilter_vf_fade_inputs[] = {
147161 {
148162 .name = "default",
@@ -168,6 +182,7 @@ AVFilter avfilter_vf_fade = { · 19 unmodified lines
168182 .description = NULL_IF_CONFIG_SMALL("Fade in/out input video"),
169183 .init = init,
170184 .priv_size = sizeof(FadeContext),
185+ .priv_class = &fade_class,
171186 .query_formats = query_formats,
172187
173188 .inputs = avfilter_vf_fade_inputs,

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