2 * Copyright (c) 2012 Stefano Sabatini
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @file framestep filter, inspired on libmpcodecs/vf_framestep.c by
23 * Daniele Fornighieri <guru AT digitalfantasy it>.
26 #include "libavutil/opt.h"
31 typedef struct NullContext
{
36 #define OFFSET(x) offsetof(FrameStepContext, x)
37 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
39 static const AVOption framestep_options
[] = {
40 { "step", "set frame step", OFFSET(frame_step
), AV_OPT_TYPE_INT
, {.i64
=1}, 1, INT_MAX
, FLAGS
},
44 AVFILTER_DEFINE_CLASS(framestep
);
46 static int config_output_props(AVFilterLink
*outlink
)
48 AVFilterContext
*ctx
= outlink
->src
;
49 FrameStepContext
*framestep
= ctx
->priv
;
50 AVFilterLink
*inlink
= ctx
->inputs
[0];
51 FilterLink
*il
= ff_filter_link(inlink
);
52 FilterLink
*ol
= ff_filter_link(outlink
);
55 av_div_q(il
->frame_rate
, (AVRational
){framestep
->frame_step
, 1});
57 av_log(ctx
, AV_LOG_VERBOSE
, "step:%d frame_rate:%d/%d(%f) -> frame_rate:%d/%d(%f)\n",
58 framestep
->frame_step
,
59 il
->frame_rate
.num
, il
->frame_rate
.den
, av_q2d(il
->frame_rate
),
60 ol
->frame_rate
.num
, ol
->frame_rate
.den
, av_q2d(ol
->frame_rate
));
64 static int filter_frame(AVFilterLink
*inlink
, AVFrame
*ref
)
66 FilterLink
*inl
= ff_filter_link(inlink
);
67 FrameStepContext
*framestep
= inlink
->dst
->priv
;
69 if (!(inl
->frame_count_out
% framestep
->frame_step
)) {
70 return ff_filter_frame(inlink
->dst
->outputs
[0], ref
);
77 static const AVFilterPad framestep_inputs
[] = {
80 .type
= AVMEDIA_TYPE_VIDEO
,
81 .filter_frame
= filter_frame
,
85 static const AVFilterPad framestep_outputs
[] = {
88 .type
= AVMEDIA_TYPE_VIDEO
,
89 .config_props
= config_output_props
,
93 const FFFilter ff_vf_framestep
= {
94 .p
.name
= "framestep",
95 .p
.description
= NULL_IF_CONFIG_SMALL("Select one frame every N frames."),
96 .p
.priv_class
= &framestep_class
,
97 .p
.flags
= AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
| AVFILTER_FLAG_METADATA_ONLY
,
98 .priv_size
= sizeof(FrameStepContext
),
99 FILTER_INPUTS(framestep_inputs
),
100 FILTER_OUTPUTS(framestep_outputs
),