| @@ -23,32 +23,25 @@ · 22 unmodified lines |
| 23 | 23 | * Daniele Fornighieri <guru AT digitalfantasy it>. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | +#include "libavutil/opt.h" |
| 26 | 27 | #include "avfilter.h" |
| 27 | 28 | #include "internal.h" |
| 28 | 29 | #include "video.h" |
| 29 | 30 | |
| 30 | 31 | typedef struct { |
| 31 | | − int frame_step, frame_count, frame_selected; |
| 32 | + const AVClass *class; |
| 33 | + int frame_step, frame_count; |
| 32 | 34 | } FrameStepContext; |
| 33 | 35 | |
| 34 | | −static av_cold int init(AVFilterContext *ctx, const char *args) |
| 35 | | −{ |
| 36 | | − FrameStepContext *framestep = ctx->priv; |
| 37 | | − char *tailptr; |
| 38 | | − long int n = 1; |
| 36 | +#define OFFSET(x) offsetof(FrameStepContext, x) |
| 37 | +#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM |
| 39 | 38 | |
| 40 | | − if (args) { |
| 41 | | − n = strtol(args, &tailptr, 10); |
| 42 | | − if (*tailptr || n <= 0 || n >= INT_MAX) { |
| 43 | | − av_log(ctx, AV_LOG_ERROR, |
| 44 | | − "Invalid argument '%s', must be a positive integer <= INT_MAX\n", args); |
| 45 | | − return AVERROR(EINVAL); |
| 46 | | − } |
| 47 | | − } |
| 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 | +}; |
| 48 | 43 | |
| 49 | | − framestep->frame_step = n; |
| 50 | | − return 0; |
| 51 | | −} |
| 44 | +AVFILTER_DEFINE_CLASS(framestep); |
| 52 | 45 | |
| 53 | 46 | static int config_output_props(AVFilterLink *outlink) |
| 54 | 47 | { |
| @@ -56,6 +49,7 @@ static int config_output_props(AVFilterLink *outlink) · 1 unmodified line |
| 56 | 49 | FrameStepContext *framestep = ctx->priv; |
| 57 | 50 | AVFilterLink *inlink = ctx->inputs[0]; |
| 58 | 51 | |
| 52 | + outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP; |
| 59 | 53 | outlink->frame_rate = |
| 60 | 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 | 65 | FrameStepContext *framestep = inlink->dst->priv; |
| 72 | 66 | |
| 73 | 67 | if (!(framestep->frame_count++ % framestep->frame_step)) { |
| 74 | | − framestep->frame_selected = 1; |
| 75 | 68 | return ff_filter_frame(inlink->dst->outputs[0], ref); |
| 76 | 69 | } else { |
| 77 | | − framestep->frame_selected = 0; |
| 78 | 70 | av_frame_free(&ref); |
| 79 | 71 | return 0; |
| 80 | 72 | } |
| 81 | 73 | } |
| 82 | 74 | |
| 83 | | −static 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 | | − |
| 97 | 75 | static const AVFilterPad framestep_inputs[] = { |
| 98 | 76 | { |
| 99 | 77 | .name = "default", |
| 100 | 78 | .type = AVMEDIA_TYPE_VIDEO, |
| 101 | | − .get_video_buffer = ff_null_get_video_buffer, |
| 102 | 79 | .filter_frame = filter_frame, |
| 103 | 80 | }, |
| 104 | 81 | { NULL } |
| @@ -109,7 +86,6 @@ static const AVFilterPad framestep_outputs[] = { · 4 unmodified lines |
| 109 | 86 | .name = "default", |
| 110 | 87 | .type = AVMEDIA_TYPE_VIDEO, |
| 111 | 88 | .config_props = config_output_props, |
| 112 | | − .request_frame = request_frame, |
| 113 | 89 | }, |
| 114 | 90 | { NULL } |
| 115 | 91 | }; |
| @@ -117,8 +93,8 @@ static const AVFilterPad framestep_outputs[] = { · 1 unmodified line |
| 117 | 93 | AVFilter avfilter_vf_framestep = { |
| 118 | 94 | .name = "framestep", |
| 119 | 95 | .description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."), |
| 120 | | − .init = init, |
| 121 | 96 | .priv_size = sizeof(FrameStepContext), |
| 97 | + .priv_class = &framestep_class, |
| 122 | 98 | .inputs = framestep_inputs, |
| 123 | 99 | .outputs = framestep_outputs, |
| 124 | 100 | }; |