vf_fade: switch to an AVOptions-based system.
This commit is contained in:
parent
8ec464c61c
commit
b9dfee9fa2
@ -1000,33 +1000,37 @@ For more information about libfreetype, check:
|
|||||||
|
|
||||||
Apply fade-in/out effect to input video.
|
Apply fade-in/out effect to input video.
|
||||||
|
|
||||||
It accepts the parameters:
|
This filter accepts the following options:
|
||||||
@var{type}:@var{start_frame}:@var{nb_frames}
|
|
||||||
|
|
||||||
@var{type} specifies if the effect type, can be either "in" for
|
@table @option
|
||||||
fade-in, or "out" for a fade-out effect.
|
|
||||||
|
|
||||||
@var{start_frame} specifies the number of the start frame for starting
|
@item type
|
||||||
to apply the fade effect.
|
The effect type -- can be either "in" for fade-in, or "out" for a fade-out
|
||||||
|
effect.
|
||||||
|
|
||||||
@var{nb_frames} specifies the number of frames for which the fade
|
@item start_frame
|
||||||
effect has to last. At the end of the fade-in effect the output video
|
The number of the start frame for starting to apply the fade effect.
|
||||||
will have the same intensity as the input video, at the end of the
|
|
||||||
fade-out transition the output video will be completely black.
|
@item nb_frames
|
||||||
|
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.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
|
||||||
A few usage examples follow, usable too as test scenarios.
|
A few usage examples follow, usable too as test scenarios.
|
||||||
@example
|
@example
|
||||||
# fade in first 30 frames of video
|
# fade in first 30 frames of video
|
||||||
fade=in:0:30
|
fade=type=in:nb_frames=30
|
||||||
|
|
||||||
# fade out last 45 frames of a 200-frame video
|
# fade out last 45 frames of a 200-frame video
|
||||||
fade=out:155:45
|
fade=type=out:start_frame=155:nb_frames=45
|
||||||
|
|
||||||
# fade in first 25 frames and fade out last 25 frames of a 1000-frame video
|
# fade in first 25 frames and fade out last 25 frames of a 1000-frame video
|
||||||
fade=in:0:25, fade=out:975:25
|
fade=type=in:start_frame=0:nb_frames=25, fade=type=out:start_frame=975:nb_frames=25
|
||||||
|
|
||||||
# make first 5 frames black, then fade in from frame 5-24
|
# make first 5 frames black, then fade in from frame 5-24
|
||||||
fade=in:5:20
|
fade=type=in:start_frame=5:nb_frames=20
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
@section fieldorder
|
@section fieldorder
|
||||||
|
@ -26,48 +26,42 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "libavutil/common.h"
|
#include "libavutil/common.h"
|
||||||
|
#include "libavutil/opt.h"
|
||||||
#include "libavutil/pixdesc.h"
|
#include "libavutil/pixdesc.h"
|
||||||
#include "avfilter.h"
|
#include "avfilter.h"
|
||||||
#include "formats.h"
|
#include "formats.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
|
|
||||||
|
#define FADE_IN 0
|
||||||
|
#define FADE_OUT 1
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
const AVClass *class;
|
||||||
|
int type;
|
||||||
int factor, fade_per_frame;
|
int factor, fade_per_frame;
|
||||||
unsigned int frame_index, start_frame, stop_frame;
|
int start_frame, nb_frames;
|
||||||
|
unsigned int frame_index, stop_frame;
|
||||||
int hsub, vsub, bpp;
|
int hsub, vsub, bpp;
|
||||||
} FadeContext;
|
} FadeContext;
|
||||||
|
|
||||||
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;
|
||||||
unsigned int nb_frames;
|
|
||||||
char in_out[4];
|
|
||||||
|
|
||||||
if (!args ||
|
fade->fade_per_frame = (1 << 16) / fade->nb_frames;
|
||||||
sscanf(args, " %3[^:]:%u:%u", in_out, &fade->start_frame, &nb_frames) != 3) {
|
if (fade->type == FADE_IN) {
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
|
||||||
"Expected 3 arguments '(in|out):#:#':'%s'\n", args);
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
nb_frames = nb_frames ? nb_frames : 1;
|
|
||||||
fade->fade_per_frame = (1 << 16) / nb_frames;
|
|
||||||
if (!strcmp(in_out, "in"))
|
|
||||||
fade->factor = 0;
|
fade->factor = 0;
|
||||||
else if (!strcmp(in_out, "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,
|
|
||||||
"first argument must be 'in' or 'out':'%s'\n", in_out);
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
}
|
||||||
fade->stop_frame = fade->start_frame + 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\n",
|
"type:%s start_frame:%d nb_frames:%d\n",
|
||||||
in_out, fade->start_frame, nb_frames);
|
fade->type == FADE_IN ? "in" : "out", fade->start_frame,
|
||||||
|
fade->nb_frames);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +137,26 @@ 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
|
||||||
|
static const AVOption 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" },
|
||||||
|
{ "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 },
|
||||||
|
{ "nb_frames", "Number of frames to which the effect should be applied.",
|
||||||
|
OFFSET(nb_frames), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, FLAGS },
|
||||||
|
{ NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
static const AVClass fade_class = {
|
||||||
|
.class_name = "fade",
|
||||||
|
.item_name = av_default_item_name,
|
||||||
|
.option = options,
|
||||||
|
.version = LIBAVUTIL_VERSION_INT,
|
||||||
|
};
|
||||||
|
|
||||||
static const AVFilterPad avfilter_vf_fade_inputs[] = {
|
static const AVFilterPad avfilter_vf_fade_inputs[] = {
|
||||||
{
|
{
|
||||||
.name = "default",
|
.name = "default",
|
||||||
@ -168,6 +182,7 @@ AVFilter avfilter_vf_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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user