FFmpeg
Loading...
Searching...
No Matches
vf_framestep.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 Stefano Sabatini
3 *
4 * This file is part of FFmpeg.
5 *
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.
10 *
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.
15 *
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
19 */
20
21/**
22 * @file framestep filter, inspired on libmpcodecs/vf_framestep.c by
23 * Daniele Fornighieri <guru AT digitalfantasy it>.
24 */
25
26#include "libavutil/opt.h"
27#include "avfilter.h"
28#include "filters.h"
29#include "video.h"
30
31typedef struct NullContext {
32 const AVClass *class;
35
36#define OFFSET(x) offsetof(FrameStepContext, x)
37#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
38
39static const AVOption framestep_options[] = {
40 { "step", "set frame step", OFFSET(frame_step), AV_OPT_TYPE_INT, {.i64=1}, 1, INT_MAX, FLAGS},
41 { NULL },
42};
43
45
47{
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);
53
54 ol->frame_rate =
55 av_div_q(il->frame_rate, (AVRational){framestep->frame_step, 1});
56
57 av_log(ctx, AV_LOG_VERBOSE, "step:%d frame_rate:%d/%d(%f) -> frame_rate:%d/%d(%f)\n",
58 framestep->frame_step,
61 return 0;
62}
63
64static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
65{
66 FilterLink *inl = ff_filter_link(inlink);
67 FrameStepContext *framestep = inlink->dst->priv;
68
69 if (!(inl->frame_count_out % framestep->frame_step)) {
70 return ff_filter_frame(inlink->dst->outputs[0], ref);
71 } else {
73 return 0;
74 }
75}
76
77static const AVFilterPad framestep_inputs[] = {
78 {
79 .name = "default",
80 .type = AVMEDIA_TYPE_VIDEO,
81 .filter_frame = filter_frame,
82 },
83};
84
86 {
87 .name = "default",
88 .type = AVMEDIA_TYPE_VIDEO,
89 .config_props = config_output_props,
90 },
91};
92
94 .p.name = "framestep",
95 .p.description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."),
96 .p.priv_class = &framestep_class,
98 .priv_size = sizeof(FrameStepContext),
101};
const FFFilter ff_vf_framestep
static AVFormatContext * ctx
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition avfilter.c:1068
Main libavfilter public API header.
#define FLAGS
Definition cmdutils.c:598
#define NULL
Definition coverity.c:32
static int filter_frame(DBEDecodeContext *s, AVFrame *frame)
Definition dolby_e.c:1067
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition avfilter.h:196
#define AVFILTER_FLAG_METADATA_ONLY
The filter is a "metadata" filter - it does not modify the frame data in any way.
Definition avfilter.h:182
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition rational.h:104
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition rational.c:88
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define FILTER_INPUTS(array)
Definition filters.h:264
#define FILTER_OUTPUTS(array)
Definition filters.h:265
static FilterLink * ff_filter_link(AVFilterLink *link)
Definition filters.h:199
#define AVFILTER_DEFINE_CLASS(fname)
Definition filters.h:478
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
AVOptions.
static int config_output_props(AVFilterLink *outlink)
Definition settb.c:72
Describe the class of an AVClass context structure.
Definition log.h:76
An instance of a filter.
Definition avfilter.h:273
void * priv
private data for use by the filter
Definition avfilter.h:288
AVFilterLink ** outputs
array of pointers to output links
Definition avfilter.h:285
A filter pad used for either input or output.
Definition filters.h:40
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVOption.
Definition opt.h:428
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
static const AVFilterPad framestep_inputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
static const AVFilterPad framestep_outputs[]
static int config_output_props(AVFilterLink *outlink)
static const AVOption framestep_options[]
#define OFFSET(x)