[FFmpeg-devel] lavfi: Add fps filter.

Clément Bœsch ubitux at gmail.com
Fri May 4 14:07:38 CEST 2012


On Fri, May 04, 2012 at 01:55:09PM +0200, Robert Nagy wrote:
> Previous mail didn't get the updated patch.

It would be nice to inline it though :)

> From d19e321a08189ef152c78b59ccb53cafcb896b9d Mon Sep 17 00:00:00 2001
> From: Robert Nagy <ronag89 at gmail.com>
> Date: Fri, 4 May 2012 10:42:34 +0200
> Subject: [PATCH] lavfi: Add fps filter.
> 
> ---
>  libavfilter/vf_fps.c |  126 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 126 insertions(+), 0 deletions(-)
>  create mode 100644 libavfilter/vf_fps.c
> 
> diff --git a/libavfilter/vf_fps.c b/libavfilter/vf_fps.c
> new file mode 100644
> index 0000000..1b201f8
> --- /dev/null
> +++ b/libavfilter/vf_fps.c
> @@ -0,0 +1,126 @@
> +/*
> + * copyright (c) 2007 Bobby Bingham
> + *

nit: "Copyright"

> + * 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.
> + *
> + * 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 FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file
> + * video framerate modification filter
> + */
> +
> +#include "libavcore/parseutils.h"

libavcore doesn't exist anymore; please build this with the latest FFmpeg.
Also since the patch is missing Makefile entry in order to test it, it's
hard to do a proper review.

> +#include "avfilter.h"
> +
> +typedef struct {
> +    AVRational			time_base;
> +    int64_t				pts;
> +    AVFilterBufferRef*	pic;

Here and all over the file: tabs are not allowed in FFmpeg, it won't pass
a git push.

> +} FPSContext;
> +
> +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> +    FPSContext *fps = ctx->priv;
> +	
> +	AVRational rate;
> +
> +	if (!args || (av_parse_video_rate(&rate, args) < 0))
> +		return -1;
> +	
> +	fps->time_base.den = rate.num;
> +	fps->time_base.num = rate.den;
> +
> +    return 0;
> +}
> +
> +static av_cold void uninit(AVFilterContext *ctx)
> +{
> +    FPSContext *fps = ctx->priv;
> +    avfilter_unref_bufferp(&fps->pic);
> +}
> +
> +static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
> +{
> +    FPSContext *fps = link->dst->priv;
> +    
> +    if(!fps->pic)

nit: here and below "if ("

> +        fps->pts = picref->pts;
> +    
> +    avfilter_unref_bufferp(&fps->pic);
> +    fps->pic = picref;
> +}
> +
> +static void end_frame(AVFilterLink *link)
> +{
> +}
> +
> +static int request_frame(AVFilterLink *link)
> +{
> +    FPSContext *fps = link->src->priv;
> +	
> +	AVRational in_time_base = link->src->inputs[0]->time_base;
> +
> +	while(!fps->pic || (fps->pic->pts*in_time_base.num*AV_TIME_BASE) / in_time_base.den < fps->pts)
> +	{

"while (...) {"

> +		int ret = avfilter_request_frame(link->src->inputs[0]);
> +        
> +        if(ret == AVERROR_EOF)
> +            avfilter_unref_bufferp(&fps->pic);
> +            
> +		if(ret < 0)
> +			return ret;
> +	}
> +	
> +	avfilter_start_frame(link, avfilter_ref_buffer(fps->pic, ~0));
> +	avfilter_draw_slice (link, 0, fps->pic->video->h, 1);
> +	avfilter_end_frame  (link);
> +		
> +	fps->pts += (fps->time_base.num*AV_TIME_BASE) / fps->time_base.den;
> +	

Some rescale functions are available, would it make sense to use them
instead?

> +	return 0;
> +}
> +
> +static int out_config_props(AVFilterLink* link)
> +{    
> +    FPSContext *fps = link->src->priv;
> +
> +	link->time_base = fps->time_base;
> +
> +    return 0;
> +}
> +
> +AVFilter avfilter_vf_fps =
> +{

style: on the same line again please: "AVFilter avfilter_vf_fps = {"

> +    .name      = "fps",
> +
> +    .init      = init,
> +    .uninit    = uninit,
> +
> +    .priv_size = sizeof(FPSContext),
> +
> +    .inputs    = (AVFilterPad[]) {{ .name            = "default",
> +                                    .type            = AVMEDIA_TYPE_VIDEO,
> +                                    .get_video_buffer= avfilter_null_get_video_buffer,
> +                                    .start_frame     = start_frame,
> +                                    .end_frame       = end_frame, },
> +                                  { .name = NULL}},
> +    .outputs   = (AVFilterPad[]) {{ .name            = "default",
> +                                    .type            = AVMEDIA_TYPE_VIDEO,
> +                                    .request_frame   = request_frame, 
> +                                    .config_props    = out_config_props},
> +                                  { .name = NULL}},
> +};
> \ No newline at end of file

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120504/dcbbb17f/attachment.asc>


More information about the ffmpeg-devel mailing list