mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-03-23 04:24:35 +02:00
lavfi/vf_fps: allow to set the rounding method.
By default, fps selects frames near PTS 0, 0.5, 1.5, 2.5, etc. With round=down, it selects the frames near PTS 0, 1, 2, 3, etc.
This commit is contained in:
parent
cc72d52dc1
commit
77a72d3485
@ -2186,6 +2186,9 @@ This filter accepts the following named parameters:
|
|||||||
@item fps
|
@item fps
|
||||||
Desired output framerate.
|
Desired output framerate.
|
||||||
|
|
||||||
|
@item round
|
||||||
|
Rounding method. The default is @code{near}.
|
||||||
|
|
||||||
@end table
|
@end table
|
||||||
|
|
||||||
@section framestep
|
@section framestep
|
||||||
|
@ -46,6 +46,7 @@ typedef struct FPSContext {
|
|||||||
|
|
||||||
AVRational framerate; ///< target framerate
|
AVRational framerate; ///< target framerate
|
||||||
char *fps; ///< a string describing target framerate
|
char *fps; ///< a string describing target framerate
|
||||||
|
int rounding; ///< AVRounding method for timestamps
|
||||||
|
|
||||||
/* statistics */
|
/* statistics */
|
||||||
int frames_in; ///< number of frames on input
|
int frames_in; ///< number of frames on input
|
||||||
@ -59,6 +60,12 @@ typedef struct FPSContext {
|
|||||||
#define F AV_OPT_FLAG_FILTERING_PARAM
|
#define F AV_OPT_FLAG_FILTERING_PARAM
|
||||||
static const AVOption fps_options[] = {
|
static const AVOption fps_options[] = {
|
||||||
{ "fps", "A string describing desired output framerate", OFFSET(fps), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = V|F },
|
{ "fps", "A string describing desired output framerate", OFFSET(fps), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = V|F },
|
||||||
|
{ "round", "set rounding method for timestamps", OFFSET(rounding), AV_OPT_TYPE_INT, { .i64 = AV_ROUND_NEAR_INF }, 0, 5, V|F, "round" },
|
||||||
|
{ "zero", "round towards 0", OFFSET(rounding), AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_ZERO }, 0, 5, V|F, "round" },
|
||||||
|
{ "inf", "round away from 0", OFFSET(rounding), AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_INF }, 0, 5, V|F, "round" },
|
||||||
|
{ "down", "round towards -infty", OFFSET(rounding), AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_DOWN }, 0, 5, V|F, "round" },
|
||||||
|
{ "up", "round towards +infty", OFFSET(rounding), AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_UP }, 0, 5, V|F, "round" },
|
||||||
|
{ "near", "round to nearest", OFFSET(rounding), AV_OPT_TYPE_CONST, { .i64 = AV_ROUND_NEAR_INF }, 0, 5, V|F, "round" },
|
||||||
{ NULL },
|
{ NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -206,8 +213,8 @@ static int end_frame(AVFilterLink *inlink)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* number of output frames */
|
/* number of output frames */
|
||||||
delta = av_rescale_q(buf->pts - s->pts, inlink->time_base,
|
delta = av_rescale_q_rnd(buf->pts - s->pts, inlink->time_base,
|
||||||
outlink->time_base);
|
outlink->time_base, s->rounding);
|
||||||
|
|
||||||
if (delta < 1) {
|
if (delta < 1) {
|
||||||
/* drop the frame and everything buffered except the first */
|
/* drop the frame and everything buffered except the first */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user