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
1000 1000
1001Apply fade-in/out effect to input video.1001Apply fade-in/out effect to input video.
1002 1002
1003It accepts the parameters:1003This filter accepts the following options:
1004@var{type}:@var{start_frame}:@var{nb_frames}1004
1005@table @option
1005 1006
1006@var{type} specifies if the effect type, can be either "in" for1007@item type
1007fade-in, or "out" for a fade-out effect.1008The effect type -- can be either "in" for fade-in, or "out" for a fade-out
1009effect.
1010
1011@item start_frame
1012The number of the start frame for starting to apply the fade effect.
1008 1013
1009@var{start_frame} specifies the number of the start frame for starting1014@item nb_frames
1010to apply the fade effect.1015The number of frames for which the fade effect has to last. At the end of the
1016fade-in effect the output video will have the same intensity as the input video,
1017at the end of the fade-out transition the output video will be completely black.
1011 1018
1012@var{nb_frames} specifies the number of frames for which the fade1019@end table
1013effect has to last. At the end of the fade-in effect the output video
1014will have the same intensity as the input video, at the end of the
1015fade-out transition the output video will be completely black.
1016 1020
1017A few usage examples follow, usable too as test scenarios.1021A few usage examples follow, usable too as test scenarios.
1018@example1022@example
1019# fade in first 30 frames of video1023# fade in first 30 frames of video
1020fade=in:0:301024fade=type=in:nb_frames=30
1021 1025
1022# fade out last 45 frames of a 200-frame video1026# fade out last 45 frames of a 200-frame video
1023fade=out:155:451027fade=type=out:start_frame=155:nb_frames=45
1024 1028
1025# fade in first 25 frames and fade out last 25 frames of a 1000-frame video1029# fade in first 25 frames and fade out last 25 frames of a 1000-frame video
1026fade=in:0:25, fade=out:975:251030fade=type=in:start_frame=0:nb_frames=25, fade=type=out:start_frame=975:nb_frames=25
1027 1031
1028# make first 5 frames black, then fade in from frame 5-241032# make first 5 frames black, then fade in from frame 5-24
1029fade=in:5:201033fade=type=in:start_frame=5:nb_frames=20
1030@end example1034@end example
1031 1035
1032@section fieldorder1036@section fieldorder
libavfilter/vf_fade.c+35−20
@@ -26,48 +26,42 @@ · 25 unmodified lines
26 */26 */
27 27
28#include "libavutil/common.h"28#include "libavutil/common.h"
29#include "libavutil/opt.h"
29#include "libavutil/pixdesc.h"30#include "libavutil/pixdesc.h"
30#include "avfilter.h"31#include "avfilter.h"
31#include "formats.h"32#include "formats.h"
32#include "internal.h"33#include "internal.h"
33#include "video.h"34#include "video.h"
34 35
36#define FADE_IN 0
37#define FADE_OUT 1
38
35typedef struct {39typedef struct {
40 const AVClass *class;
41 int type;
36 int factor, fade_per_frame;42 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;
38 int hsub, vsub, bpp;45 int hsub, vsub, bpp;
39} FadeContext;46} FadeContext;
40 47
41static av_cold int init(AVFilterContext *ctx, const char *args)48static av_cold int init(AVFilterContext *ctx, const char *args)
42{49{
43 FadeContext *fade = ctx->priv;50 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 }
53 51
54 nb_frames = nb_frames ? nb_frames : 1;52 fade->fade_per_frame = (1 << 16) / fade->nb_frames;
55 fade->fade_per_frame = (1 << 16) / nb_frames;53 if (fade->type == FADE_IN) {
56 if (!strcmp(in_out, "in"))
57 fade->factor = 0;54 fade->factor = 0;
58 else if (!strcmp(in_out, "out")) {55 } else if (fade->type == FADE_OUT) {
59 fade->fade_per_frame = -fade->fade_per_frame;56 fade->fade_per_frame = -fade->fade_per_frame;
60 fade->factor = (1 << 16);57 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);
65 }58 }
66 fade->stop_frame = fade->start_frame + nb_frames;59 fade->stop_frame = fade->start_frame + fade->nb_frames;
67 60
68 av_log(ctx, AV_LOG_VERBOSE,61 av_log(ctx, AV_LOG_VERBOSE,
69 "type:%s start_frame:%d nb_frames:%d\n",62 "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);
71 return 0;65 return 0;
72}66}
73 67
@@ -143,6 +137,26 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 69 unmodified lines
143 return ff_filter_frame(inlink->dst->outputs[0], frame);137 return ff_filter_frame(inlink->dst->outputs[0], frame);
144}138}
145 139
140#define OFFSET(x) offsetof(FadeContext, x)
141#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
142static 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
153static 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
146static const AVFilterPad avfilter_vf_fade_inputs[] = {160static const AVFilterPad avfilter_vf_fade_inputs[] = {
147 {161 {
148 .name = "default",162 .name = "default",
@@ -168,6 +182,7 @@ AVFilter avfilter_vf_fade = { · 19 unmodified lines
168 .description = NULL_IF_CONFIG_SMALL("Fade in/out input video"),182 .description = NULL_IF_CONFIG_SMALL("Fade in/out input video"),
169 .init = init,183 .init = init,
170 .priv_size = sizeof(FadeContext),184 .priv_size = sizeof(FadeContext),
185 .priv_class = &fade_class,
171 .query_formats = query_formats,186 .query_formats = query_formats,
172 187
173 .inputs = avfilter_vf_fade_inputs,188 .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