| @@ -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 | |
| 30 | typedef struct { | 31 | typedef 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 | |
| 34 | static 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) { | 39 | static 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; | 44 | AVFILTER_DEFINE_CLASS(framestep); |
| 50 | return 0; | | |
| 51 | } | | |
| 52 | | 45 | |
| 53 | static int config_output_props(AVFilterLink *outlink) | 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 | 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 | |
| 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 | static const AVFilterPad framestep_inputs[] = { | 75 | static 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 |
| 117 | AVFilter avfilter_vf_framestep = { | 93 | AVFilter 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 | }; |