Commit 0c3d706b authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit 'b9dfee9f'

* commit 'b9dfee9f':
  vf_fade: switch to an AVOptions-based system.

Conflicts:
	doc/filters.texi
	libavfilter/vf_fade.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents d70b4944 b9dfee9f
...@@ -3036,27 +3036,23 @@ edgedetect=low=0.1:high=0.4 ...@@ -3036,27 +3036,23 @@ edgedetect=low=0.1:high=0.4
Apply fade-in/out effect to input video. Apply fade-in/out effect to input video.
The filter accepts parameters as a list of @var{key}=@var{value} This filter accepts the following options:
pairs, separated by ":". If the key of the first options is omitted,
the arguments are interpreted according to the syntax
@var{type}:@var{start_frame}:@var{nb_frames}.
A description of the accepted parameters follows.
@table @option @table @option
@item type, t @item type, t
Specify if the effect type, can be either @code{in} for fade-in, or The effect type -- can be either "in" for fade-in, or "out" for a fade-out
@code{out} for a fade-out effect. Default is @code{in}. effect.
Default is @code{in}.
@item start_frame, s @item start_frame, s
Specify the number of the start frame for starting to apply the fade Specify the number of the start frame for starting to apply the fade
effect. Default is 0. effect. Default is 0.
@item nb_frames, n @item nb_frames, n
Specify the number of frames for which the fade effect has to last. At The number of frames for which the fade effect has to last. At the end of the
the end of the fade-in effect the output video will have the same fade-in effect the output video will have the same intensity as the input video,
intensity as the input video, at the end of the fade-out transition at the end of the fade-out transition the output video will be completely black.
the output video will be completely black. Default is 25. Default is 25.
@item alpha @item alpha
If set to 1, fade only alpha channel, if one exists on the input. 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 ...@@ -3081,6 +3077,7 @@ fade=t=in:s=0:n=30
Fade out last 45 frames of a 200-frame video: Fade out last 45 frames of a 200-frame video:
@example @example
fade=out:155:45 fade=out:155:45
fade=type=out:start_frame=155:nb_frames=45
@end example @end example
@item @item
......
...@@ -664,6 +664,7 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque ...@@ -664,6 +664,7 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
!strcmp(filter->filter->name, "delogo" ) || !strcmp(filter->filter->name, "delogo" ) ||
!strcmp(filter->filter->name, "drawbox" ) || !strcmp(filter->filter->name, "drawbox" ) ||
!strcmp(filter->filter->name, "drawtext" ) || !strcmp(filter->filter->name, "drawtext" ) ||
!strcmp(filter->filter->name, "fade" ) ||
!strcmp(filter->filter->name, "format") || !strcmp(filter->filter->name, "format") ||
!strcmp(filter->filter->name, "noformat") || !strcmp(filter->filter->name, "noformat") ||
!strcmp(filter->filter->name, "resample") !strcmp(filter->filter->name, "resample")
......
...@@ -46,55 +46,40 @@ ...@@ -46,55 +46,40 @@
#define U 1 #define U 1
#define V 2 #define V 2
#define FADE_IN 0
#define FADE_OUT 1
typedef struct { typedef struct {
const AVClass *class; const AVClass *class;
int type;
int factor, fade_per_frame; int factor, fade_per_frame;
unsigned int frame_index, start_frame, stop_frame, nb_frames; int start_frame, nb_frames;
unsigned int frame_index, stop_frame;
int hsub, vsub, bpp; int hsub, vsub, bpp;
unsigned int black_level, black_level_scaled; unsigned int black_level, black_level_scaled;
uint8_t is_packed_rgb; uint8_t is_packed_rgb;
uint8_t rgba_map[4]; uint8_t rgba_map[4];
int alpha; int alpha;
char *type;
} FadeContext; } FadeContext;
#define OFFSET(x) offsetof(FadeContext, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
static const AVOption fade_options[] = {
{ "type", "set the fade direction", OFFSET(type), AV_OPT_TYPE_STRING, {.str = "in" }, CHAR_MIN, CHAR_MAX, FLAGS },
{ "t", "set the fade direction", OFFSET(type), AV_OPT_TYPE_STRING, {.str = "in" }, CHAR_MIN, CHAR_MAX, FLAGS },
{ "start_frame", "set expression of frame to start fading", OFFSET(start_frame), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, FLAGS },
{ "s", "set expression of frame to start fading", OFFSET(start_frame), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, FLAGS },
{ "nb_frames", "set expression for fade duration in frames", OFFSET(nb_frames), AV_OPT_TYPE_INT, {.i64 = 25 }, 0, INT_MAX, FLAGS },
{ "n", "set expression for fade duration in frames", OFFSET(nb_frames), AV_OPT_TYPE_INT, {.i64 = 25 }, 0, INT_MAX, FLAGS },
{ "alpha", "fade alpha if it is available on the input", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, FLAGS },
{NULL},
};
AVFILTER_DEFINE_CLASS(fade);
static av_cold int init(AVFilterContext *ctx, const char *args) static av_cold int init(AVFilterContext *ctx, const char *args)
{ {
FadeContext *fade = ctx->priv; FadeContext *fade = ctx->priv;
fade->fade_per_frame = (1 << 16) / fade->nb_frames; fade->fade_per_frame = (1 << 16) / fade->nb_frames;
if (!strcmp(fade->type, "in")) if (fade->type == FADE_IN) {
fade->factor = 0; fade->factor = 0;
else if (!strcmp(fade->type, "out")) { } else if (fade->type == FADE_OUT) {
fade->fade_per_frame = -fade->fade_per_frame; fade->fade_per_frame = -fade->fade_per_frame;
fade->factor = (1 << 16); fade->factor = (1 << 16);
} else {
av_log(ctx, AV_LOG_ERROR,
"Type argument must be 'in' or 'out' but '%s' was specified\n", fade->type);
return AVERROR(EINVAL);
} }
fade->stop_frame = fade->start_frame + fade->nb_frames; fade->stop_frame = fade->start_frame + fade->nb_frames;
av_log(ctx, AV_LOG_VERBOSE, av_log(ctx, AV_LOG_VERBOSE,
"type:%s start_frame:%d nb_frames:%d alpha:%d\n", "type:%s start_frame:%d nb_frames:%d alpha:%d\n",
fade->type, fade->start_frame, fade->nb_frames, fade->alpha); fade->type == FADE_IN ? "in" : "out", fade->start_frame,
fade->nb_frames, fade->alpha);
return 0; return 0;
} }
...@@ -212,6 +197,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) ...@@ -212,6 +197,29 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
return ff_filter_frame(inlink->dst->outputs[0], frame); return ff_filter_frame(inlink->dst->outputs[0], frame);
} }
#define OFFSET(x) offsetof(FadeContext, x)
#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
static const AVOption fade_options[] = {
{ "type", "'in' or 'out' for fade-in/fade-out", OFFSET(type), AV_OPT_TYPE_INT, { .i64 = FADE_IN }, FADE_IN, FADE_OUT, FLAGS, "type" },
{ "t", "'in' or 'out' for fade-in/fade-out", OFFSET(type), AV_OPT_TYPE_INT, { .i64 = FADE_IN }, FADE_IN, FADE_OUT, FLAGS, "type" },
{ "in", "fade-in", 0, AV_OPT_TYPE_CONST, { .i64 = FADE_IN }, .unit = "type" },
{ "out", "fade-out", 0, AV_OPT_TYPE_CONST, { .i64 = FADE_OUT }, .unit = "type" },
{ "start_frame", "Number of the first frame to which to apply the effect.",
OFFSET(start_frame), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ "s", "Number of the first frame to which to apply the effect.",
OFFSET(start_frame), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS },
{ "nb_frames", "Number of frames to which the effect should be applied.",
OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, FLAGS },
{ "n", "Number of frames to which the effect should be applied.",
OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, FLAGS },
{ "alpha", "fade alpha if it is available on the input", OFFSET(alpha), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 1, FLAGS },
{ NULL },
};
AVFILTER_DEFINE_CLASS(fade);
static const AVFilterPad avfilter_vf_fade_inputs[] = { static const AVFilterPad avfilter_vf_fade_inputs[] = {
{ {
.name = "default", .name = "default",
...@@ -232,17 +240,14 @@ static const AVFilterPad avfilter_vf_fade_outputs[] = { ...@@ -232,17 +240,14 @@ static const AVFilterPad avfilter_vf_fade_outputs[] = {
{ NULL } { NULL }
}; };
static const char *const shorthand[] = { "type", "start_frame", "nb_frames", NULL };
AVFilter avfilter_vf_fade = { AVFilter avfilter_vf_fade = {
.name = "fade", .name = "fade",
.description = NULL_IF_CONFIG_SMALL("Fade in/out input video."), .description = NULL_IF_CONFIG_SMALL("Fade in/out input video."),
.init = init, .init = init,
.priv_size = sizeof(FadeContext), .priv_size = sizeof(FadeContext),
.priv_class = &fade_class,
.query_formats = query_formats, .query_formats = query_formats,
.inputs = avfilter_vf_fade_inputs, .inputs = avfilter_vf_fade_inputs,
.outputs = avfilter_vf_fade_outputs, .outputs = avfilter_vf_fade_outputs,
.priv_class = &fade_class,
.shorthand = shorthand,
}; };
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment