FFmpeg
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 "internal.h"
29 #include "video.h"
30 
31 typedef struct NullContext {
32  const AVClass *class;
34 } FrameStepContext;
35 
36 #define OFFSET(x) offsetof(FrameStepContext, x)
37 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
38 
39 static 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 
44 AVFILTER_DEFINE_CLASS(framestep);
45 
46 static int config_output_props(AVFilterLink *outlink)
47 {
48  AVFilterContext *ctx = outlink->src;
49  FrameStepContext *framestep = ctx->priv;
50  AVFilterLink *inlink = ctx->inputs[0];
51 
52  outlink->frame_rate =
53  av_div_q(inlink->frame_rate, (AVRational){framestep->frame_step, 1});
54 
55  av_log(ctx, AV_LOG_VERBOSE, "step:%d frame_rate:%d/%d(%f) -> frame_rate:%d/%d(%f)\n",
56  framestep->frame_step,
57  inlink->frame_rate.num, inlink->frame_rate.den, av_q2d(inlink->frame_rate),
58  outlink->frame_rate.num, outlink->frame_rate.den, av_q2d(outlink->frame_rate));
59  return 0;
60 }
61 
63 {
64  FrameStepContext *framestep = inlink->dst->priv;
65 
66  if (!(inlink->frame_count_out % framestep->frame_step)) {
67  return ff_filter_frame(inlink->dst->outputs[0], ref);
68  } else {
70  return 0;
71  }
72 }
73 
74 static const AVFilterPad framestep_inputs[] = {
75  {
76  .name = "default",
77  .type = AVMEDIA_TYPE_VIDEO,
78  .filter_frame = filter_frame,
79  },
80  { NULL }
81 };
82 
83 static const AVFilterPad framestep_outputs[] = {
84  {
85  .name = "default",
86  .type = AVMEDIA_TYPE_VIDEO,
87  .config_props = config_output_props,
88  },
89  { NULL }
90 };
91 
93  .name = "framestep",
94  .description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."),
95  .priv_size = sizeof(FrameStepContext),
96  .priv_class = &framestep_class,
100 };
opt.h
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
av_div_q
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
Definition: rational.c:88
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption
AVOption.
Definition: opt.h:246
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
Definition: vf_framestep.c:62
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
video.h
ff_vf_framestep
AVFilter ff_vf_framestep
Definition: vf_framestep.c:92
config_output_props
static int config_output_props(AVFilterLink *outlink)
Definition: vf_framestep.c:46
AVRational::num
int num
Numerator.
Definition: rational.h:59
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
framestep_inputs
static const AVFilterPad framestep_inputs[]
Definition: vf_framestep.c:74
av_q2d
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
OFFSET
#define OFFSET(x)
Definition: vf_framestep.c:36
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
framestep_outputs
static const AVFilterPad framestep_outputs[]
Definition: vf_framestep.c:83
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:125
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AVFilter
Filter definition.
Definition: avfilter.h:144
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(framestep)
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:223
avfilter.h
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
NullContext
Definition: vf_framestep.c:31
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
framestep_options
static const AVOption framestep_options[]
Definition: vf_framestep.c:39
FLAGS
#define FLAGS
Definition: vf_framestep.c:37
NullContext::frame_step
int frame_step
Definition: vf_framestep.c:33
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:565
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28