History

Merge remote-tracking branch 'richardpl/framestep'

* richardpl/framestep: lavfi/framestep: remove request_frame hack lavfi/framestep: switch to an AVOptions-based system

Michael Niedermayer committed 13 years ago

Commit 5e5ef6e2 parents f17651b 7c79ec63 files · +20 −39Browse files

Unified · Split

3 files
  1. doc/filters.texi +7 −3
  2. libavfilter/avfilter.c +1 −0
  3. libavfilter/vf_framestep.c +12 −36
doc/filters.texi+7−3
@@ -3212,10 +3212,14 @@ See also the @ref{setpts} filter. · 3211 unmodified lines
3212 3212
3213@section framestep3213@section framestep
3214 3214
3215Select one frame every N.3215Select one frame every N-th frame.
3216 3216
3217This filter accepts in input a string representing a positive3217This filter accepts the following option:
3218integer. Default argument is @code{1}.3218@table @option
3219@item step
3220Select frame after every @code{step} frames.
3221Allowed values are positive integers higher than 0. Default value is @code{1}.
3222@end table
3219 3223
3220@anchor{frei0r}3224@anchor{frei0r}
3221@section frei0r3225@section frei0r
libavfilter/avfilter.c+1−0
@@ -683,6 +683,7 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque · 682 unmodified lines
683 !strcmp(filter->filter->name, "field" ) ||683 !strcmp(filter->filter->name, "field" ) ||
684 !strcmp(filter->filter->name, "fieldorder") ||684 !strcmp(filter->filter->name, "fieldorder") ||
685 !strcmp(filter->filter->name, "fps" ) ||685 !strcmp(filter->filter->name, "fps" ) ||
686 !strcmp(filter->filter->name, "framestep" ) ||
686 !strcmp(filter->filter->name, "frei0r" ) ||687 !strcmp(filter->filter->name, "frei0r" ) ||
687 !strcmp(filter->filter->name, "frei0r_src") ||688 !strcmp(filter->filter->name, "frei0r_src") ||
688 !strcmp(filter->filter->name, "geq" ) ||689 !strcmp(filter->filter->name, "geq" ) ||
libavfilter/vf_framestep.c+12−36
@@ -23,32 +23,25 @@ · 22 unmodified lines
23 * Daniele Fornighieri <guru AT digitalfantasy it>.23 * Daniele Fornighieri <guru AT digitalfantasy it>.
24 */24 */
25 25
26#include "libavutil/opt.h"
26#include "avfilter.h"27#include "avfilter.h"
27#include "internal.h"28#include "internal.h"
28#include "video.h"29#include "video.h"
29 30
30typedef struct {31typedef struct {
31 int frame_step, frame_count, frame_selected;32 const AVClass *class;
33 int frame_step, frame_count;
32} FrameStepContext;34} FrameStepContext;
33 35
34static av_cold int init(AVFilterContext *ctx, const char *args)36#define OFFSET(x) offsetof(FrameStepContext, x)
35{37#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
36 FrameStepContext *framestep = ctx->priv;
37 char *tailptr;
38 long int n = 1;
39 38
40 if (args) {39static const AVOption framestep_options[] = {
41 n = strtol(args, &tailptr, 10);40 { "step", "set frame step", OFFSET(frame_step), AV_OPT_TYPE_INT, {.i64=1}, 1, INT_MAX, FLAGS},
42 if (*tailptr || n <= 0 || n >= INT_MAX) {41 {NULL},
43 av_log(ctx, AV_LOG_ERROR,42};
44 "Invalid argument '%s', must be a positive integer <= INT_MAX\n", args);
45 return AVERROR(EINVAL);
46 }
47 }
48 43
49 framestep->frame_step = n;44AVFILTER_DEFINE_CLASS(framestep);
50 return 0;
51}
52 45
53static int config_output_props(AVFilterLink *outlink)46static int config_output_props(AVFilterLink *outlink)
54{47{
@@ -56,6 +49,7 @@ static int config_output_props(AVFilterLink *outlink) · 1 unmodified line
56 FrameStepContext *framestep = ctx->priv;49 FrameStepContext *framestep = ctx->priv;
57 AVFilterLink *inlink = ctx->inputs[0];50 AVFilterLink *inlink = ctx->inputs[0];
58 51
52 outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
59 outlink->frame_rate =53 outlink->frame_rate =
60 av_div_q(inlink->frame_rate, (AVRational){framestep->frame_step, 1});54 av_div_q(inlink->frame_rate, (AVRational){framestep->frame_step, 1});
61 55
@@ -71,34 +65,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *ref) · 9 unmodified lines
71 FrameStepContext *framestep = inlink->dst->priv;65 FrameStepContext *framestep = inlink->dst->priv;
72 66
73 if (!(framestep->frame_count++ % framestep->frame_step)) {67 if (!(framestep->frame_count++ % framestep->frame_step)) {
74 framestep->frame_selected = 1;
75 return ff_filter_frame(inlink->dst->outputs[0], ref);68 return ff_filter_frame(inlink->dst->outputs[0], ref);
76 } else {69 } else {
77 framestep->frame_selected = 0;
78 av_frame_free(&ref);70 av_frame_free(&ref);
79 return 0;71 return 0;
80 }72 }
81}73}
82 74
83static int request_frame(AVFilterLink *outlink)
84{
85 FrameStepContext *framestep = outlink->src->priv;
86 AVFilterLink *inlink = outlink->src->inputs[0];
87 int ret;
88
89 framestep->frame_selected = 0;
90 do {
91 ret = ff_request_frame(inlink);
92 } while (!framestep->frame_selected && ret >= 0);
93
94 return ret;
95}
96
97static const AVFilterPad framestep_inputs[] = {75static const AVFilterPad framestep_inputs[] = {
98 {76 {
99 .name = "default",77 .name = "default",
100 .type = AVMEDIA_TYPE_VIDEO,78 .type = AVMEDIA_TYPE_VIDEO,
101 .get_video_buffer = ff_null_get_video_buffer,
102 .filter_frame = filter_frame,79 .filter_frame = filter_frame,
103 },80 },
104 { NULL }81 { NULL }
@@ -109,7 +86,6 @@ static const AVFilterPad framestep_outputs[] = { · 4 unmodified lines
109 .name = "default",86 .name = "default",
110 .type = AVMEDIA_TYPE_VIDEO,87 .type = AVMEDIA_TYPE_VIDEO,
111 .config_props = config_output_props,88 .config_props = config_output_props,
112 .request_frame = request_frame,
113 },89 },
114 { NULL }90 { NULL }
115};91};
@@ -117,8 +93,8 @@ static const AVFilterPad framestep_outputs[] = { · 1 unmodified line
117AVFilter avfilter_vf_framestep = {93AVFilter avfilter_vf_framestep = {
118 .name = "framestep",94 .name = "framestep",
119 .description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."),95 .description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."),
120 .init = init,
121 .priv_size = sizeof(FrameStepContext),96 .priv_size = sizeof(FrameStepContext),
97 .priv_class = &framestep_class,
122 .inputs = framestep_inputs,98 .inputs = framestep_inputs,
123 .outputs = framestep_outputs,99 .outputs = framestep_outputs,
124};100};

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t