diff options
Diffstat (limited to 'libavfilter/vf_fps.c')
-rw-r--r-- | libavfilter/vf_fps.c | 51 |
1 files changed, 30 insertions, 21 deletions
diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c index 8fd51bd..29eedc7 100644 --- a/libavfilter/vf_fps.c +++ b/libavfilter/vf_fps.c @@ -1,18 +1,22 @@ /* - * This file is part of Libav. + * Copyright 2007 Bobby Bingham + * Copyright 2012 Robert Nagy <ronag89 gmail com> + * Copyright 2012 Anton Khirnov <anton khirnov net> * - * Libav is free software; you can redistribute it and/or + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -42,6 +46,7 @@ typedef struct FPSContext { AVRational framerate; ///< target framerate char *fps; ///< a string describing target framerate + int rounding; ///< AVRounding method for timestamps /* statistics */ int frames_in; ///< number of frames on input @@ -52,31 +57,31 @@ typedef struct FPSContext { #define OFFSET(x) offsetof(FPSContext, x) #define V AV_OPT_FLAG_VIDEO_PARAM -static const AVOption options[] = { - { "fps", "A string describing desired output framerate", OFFSET(fps), AV_OPT_TYPE_STRING, { .str = "25" }, .flags = V }, +#define F AV_OPT_FLAG_FILTERING_PARAM +static const AVOption fps_options[] = { + { "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 }, }; -static const AVClass class = { - .class_name = "FPS filter", - .item_name = av_default_item_name, - .option = options, - .version = LIBAVUTIL_VERSION_INT, -}; +AVFILTER_DEFINE_CLASS(fps); static av_cold int init(AVFilterContext *ctx, const char *args) { FPSContext *s = ctx->priv; + const char *shorthand[] = { "fps", "round", NULL }; int ret; - s->class = &class; + s->class = &fps_class; av_opt_set_defaults(s); - if ((ret = av_set_options_string(s, args, "=", ":")) < 0) { - av_log(ctx, AV_LOG_ERROR, "Error parsing the options string %s.\n", - args); + if ((ret = av_opt_set_from_string(s, args, shorthand, "=", ":")) < 0) return ret; - } if ((ret = av_parse_video_rate(&s->framerate, s->fps)) < 0) { av_log(ctx, AV_LOG_ERROR, "Error parsing framerate %s.\n", s->fps); @@ -117,7 +122,8 @@ static int config_props(AVFilterLink* link) { FPSContext *s = link->src->priv; - link->time_base = (AVRational){ s->framerate.den, s->framerate.num }; + link->time_base = av_inv_q(s->framerate); + link->frame_rate= s->framerate; link->w = link->src->inputs[0]->w; link->h = link->src->inputs[0]->h; s->pts = AV_NOPTS_VALUE; @@ -202,8 +208,8 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf) } /* number of output frames */ - delta = av_rescale_q(buf->pts - s->pts, inlink->time_base, - outlink->time_base); + delta = av_rescale_q_rnd(buf->pts - s->pts, inlink->time_base, + outlink->time_base, s->rounding); if (delta < 1) { /* drop the frame and everything buffered except the first */ @@ -228,7 +234,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *buf) /* duplicate the frame if needed */ if (!av_fifo_size(s->fifo) && i < delta - 1) { - AVFilterBufferRef *dup = avfilter_ref_buffer(buf_out, AV_PERM_READ); + AVFilterBufferRef *dup = avfilter_ref_buffer(buf_out, ~0); av_log(ctx, AV_LOG_DEBUG, "Duplicating frame.\n"); if (dup) @@ -267,6 +273,7 @@ static const AVFilterPad avfilter_vf_fps_inputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, + .min_perms = AV_PERM_READ | AV_PERM_PRESERVE, .filter_frame = filter_frame, }, { NULL } @@ -276,6 +283,7 @@ static const AVFilterPad avfilter_vf_fps_outputs[] = { { .name = "default", .type = AVMEDIA_TYPE_VIDEO, + .rej_perms = AV_PERM_WRITE, .request_frame = request_frame, .config_props = config_props }, @@ -293,4 +301,5 @@ AVFilter avfilter_vf_fps = { .inputs = avfilter_vf_fps_inputs, .outputs = avfilter_vf_fps_outputs, + .priv_class = &fps_class, }; |