Merge remote-tracking branch 'richardpl/framestep'
* richardpl/framestep: lavfi/framestep: remove request_frame hack lavfi/framestep: switch to an AVOptions-based system Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
5e5ef6e8ae
@ -3212,10 +3212,14 @@ See also the @ref{setpts} filter.
|
|||||||
|
|
||||||
@section framestep
|
@section framestep
|
||||||
|
|
||||||
Select one frame every N.
|
Select one frame every N-th frame.
|
||||||
|
|
||||||
This filter accepts in input a string representing a positive
|
This filter accepts the following option:
|
||||||
integer. Default argument is @code{1}.
|
@table @option
|
||||||
|
@item step
|
||||||
|
Select frame after every @code{step} frames.
|
||||||
|
Allowed values are positive integers higher than 0. Default value is @code{1}.
|
||||||
|
@end table
|
||||||
|
|
||||||
@anchor{frei0r}
|
@anchor{frei0r}
|
||||||
@section frei0r
|
@section frei0r
|
||||||
|
@ -683,6 +683,7 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque
|
|||||||
!strcmp(filter->filter->name, "field" ) ||
|
!strcmp(filter->filter->name, "field" ) ||
|
||||||
!strcmp(filter->filter->name, "fieldorder") ||
|
!strcmp(filter->filter->name, "fieldorder") ||
|
||||||
!strcmp(filter->filter->name, "fps" ) ||
|
!strcmp(filter->filter->name, "fps" ) ||
|
||||||
|
!strcmp(filter->filter->name, "framestep" ) ||
|
||||||
!strcmp(filter->filter->name, "frei0r" ) ||
|
!strcmp(filter->filter->name, "frei0r" ) ||
|
||||||
!strcmp(filter->filter->name, "frei0r_src") ||
|
!strcmp(filter->filter->name, "frei0r_src") ||
|
||||||
!strcmp(filter->filter->name, "geq" ) ||
|
!strcmp(filter->filter->name, "geq" ) ||
|
||||||
|
@ -23,32 +23,25 @@
|
|||||||
* Daniele Fornighieri <guru AT digitalfantasy it>.
|
* Daniele Fornighieri <guru AT digitalfantasy it>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "libavutil/opt.h"
|
||||||
#include "avfilter.h"
|
#include "avfilter.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "video.h"
|
#include "video.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int frame_step, frame_count, frame_selected;
|
const AVClass *class;
|
||||||
|
int frame_step, frame_count;
|
||||||
} FrameStepContext;
|
} FrameStepContext;
|
||||||
|
|
||||||
static av_cold int init(AVFilterContext *ctx, const char *args)
|
#define OFFSET(x) offsetof(FrameStepContext, x)
|
||||||
{
|
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
|
||||||
FrameStepContext *framestep = ctx->priv;
|
|
||||||
char *tailptr;
|
|
||||||
long int n = 1;
|
|
||||||
|
|
||||||
if (args) {
|
static const AVOption framestep_options[] = {
|
||||||
n = strtol(args, &tailptr, 10);
|
{ "step", "set frame step", OFFSET(frame_step), AV_OPT_TYPE_INT, {.i64=1}, 1, INT_MAX, FLAGS},
|
||||||
if (*tailptr || n <= 0 || n >= INT_MAX) {
|
{NULL},
|
||||||
av_log(ctx, AV_LOG_ERROR,
|
};
|
||||||
"Invalid argument '%s', must be a positive integer <= INT_MAX\n", args);
|
|
||||||
return AVERROR(EINVAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
framestep->frame_step = n;
|
AVFILTER_DEFINE_CLASS(framestep);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int config_output_props(AVFilterLink *outlink)
|
static int config_output_props(AVFilterLink *outlink)
|
||||||
{
|
{
|
||||||
@ -56,6 +49,7 @@ static int config_output_props(AVFilterLink *outlink)
|
|||||||
FrameStepContext *framestep = ctx->priv;
|
FrameStepContext *framestep = ctx->priv;
|
||||||
AVFilterLink *inlink = ctx->inputs[0];
|
AVFilterLink *inlink = ctx->inputs[0];
|
||||||
|
|
||||||
|
outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
|
||||||
outlink->frame_rate =
|
outlink->frame_rate =
|
||||||
av_div_q(inlink->frame_rate, (AVRational){framestep->frame_step, 1});
|
av_div_q(inlink->frame_rate, (AVRational){framestep->frame_step, 1});
|
||||||
|
|
||||||
@ -71,34 +65,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *ref)
|
|||||||
FrameStepContext *framestep = inlink->dst->priv;
|
FrameStepContext *framestep = inlink->dst->priv;
|
||||||
|
|
||||||
if (!(framestep->frame_count++ % framestep->frame_step)) {
|
if (!(framestep->frame_count++ % framestep->frame_step)) {
|
||||||
framestep->frame_selected = 1;
|
|
||||||
return ff_filter_frame(inlink->dst->outputs[0], ref);
|
return ff_filter_frame(inlink->dst->outputs[0], ref);
|
||||||
} else {
|
} else {
|
||||||
framestep->frame_selected = 0;
|
|
||||||
av_frame_free(&ref);
|
av_frame_free(&ref);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int request_frame(AVFilterLink *outlink)
|
|
||||||
{
|
|
||||||
FrameStepContext *framestep = outlink->src->priv;
|
|
||||||
AVFilterLink *inlink = outlink->src->inputs[0];
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
framestep->frame_selected = 0;
|
|
||||||
do {
|
|
||||||
ret = ff_request_frame(inlink);
|
|
||||||
} while (!framestep->frame_selected && ret >= 0);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const AVFilterPad framestep_inputs[] = {
|
static const AVFilterPad framestep_inputs[] = {
|
||||||
{
|
{
|
||||||
.name = "default",
|
.name = "default",
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
.get_video_buffer = ff_null_get_video_buffer,
|
|
||||||
.filter_frame = filter_frame,
|
.filter_frame = filter_frame,
|
||||||
},
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
@ -109,7 +86,6 @@ static const AVFilterPad framestep_outputs[] = {
|
|||||||
.name = "default",
|
.name = "default",
|
||||||
.type = AVMEDIA_TYPE_VIDEO,
|
.type = AVMEDIA_TYPE_VIDEO,
|
||||||
.config_props = config_output_props,
|
.config_props = config_output_props,
|
||||||
.request_frame = request_frame,
|
|
||||||
},
|
},
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
@ -117,8 +93,8 @@ static const AVFilterPad framestep_outputs[] = {
|
|||||||
AVFilter avfilter_vf_framestep = {
|
AVFilter avfilter_vf_framestep = {
|
||||||
.name = "framestep",
|
.name = "framestep",
|
||||||
.description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."),
|
.description = NULL_IF_CONFIG_SMALL("Select one frame every N frames."),
|
||||||
.init = init,
|
|
||||||
.priv_size = sizeof(FrameStepContext),
|
.priv_size = sizeof(FrameStepContext),
|
||||||
|
.priv_class = &framestep_class,
|
||||||
.inputs = framestep_inputs,
|
.inputs = framestep_inputs,
|
||||||
.outputs = framestep_outputs,
|
.outputs = framestep_outputs,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user