[FFmpeg-devel] [PATCH 4/5] Add setpts filter by Victor Paesa.

Víctor Paesa victorpaesa
Mon Oct 11 17:43:14 CEST 2010


Hi,

First of all, thanks a lot for pushing this.

On Mon, Oct 11, 2010 at 12:19, Stefano Sabatini wrote:
> ---
> ?doc/filters.texi ? ? ? ? | ? 46 +++++++++++++++
> ?libavfilter/Makefile ? ? | ? ?1 +
> ?libavfilter/allfilters.c | ? ?1 +
> ?libavfilter/vf_setpts.c ?| ?143 ++++++++++++++++++++++++++++++++++++++++++++++
> ?4 files changed, 191 insertions(+), 0 deletions(-)
> ?create mode 100644 libavfilter/vf_setpts.c
>
> diff --git a/doc/filters.texi b/doc/filters.texi
> index 3c3285e..384500f 100644
> --- a/doc/filters.texi
> +++ b/doc/filters.texi
> @@ -457,6 +457,52 @@ settb=2*intb
> ?settb=AVTB
> ?@end example
>
> + at section setpts
> +
> +Change the PTS (presentation timestamp) of the input video frames.
> +
> +Accept in input an expression evaluated through the eval API, which
> +can contain the following constants:
> +
> + at table @option
> + at item PTS
> +the presentation timestamp in input
> +
> + at item PI
> +Greek PI
> +
> + at item E
> +Euler number
> +
> + at item AVTB
> +the FFmpeg Time Base
> +
> + at item N
> +the count of the input frame, starting from 0.
> +
> + at item STARTPTS
> +the PTS of the first video frame
> + at end table
> +

Docs missing for
+    "INTERLACED"  ///< tell if the current frame is interlaced
+    "NOPTS"       ///< value corresponding to an undefined PTS
+    "POS",        ///< original position in the file of the frame
+    "PREV_INPTS"  ///< previous  input PTS
+    "PREV_OUTPTS" ///< previous output PTS

> +Follows some examples:
> +

"Some examples follow:"

> + at example
> +# Start counting PTS from zero
> +setpts=PTS-STARTPTS
> +
> +# Fast motion
> +setpts=0.5*PTS
> +
> +# Slow motion
> +setpts=2.0*PTS
> +?
> +# Fixed rate 25 fps
> +setpts=N*AVTB/25
> +
> +# Fixed rate 25 fps with some jitter
> +setpts='AVTB/25 * (N+0.05 * sin (N*2*PI/25))'
> + at end example
> +

Here or somewhere in the docs: 'Remember to use "-vsync 0", and to
avoid "-copyts".'

> ?@section slicify
>
> ?Pass the images of input video on to next video filter as multiple
> diff --git a/libavfilter/Makefile b/libavfilter/Makefile
> index 597e532..20f9c1e 100644
> --- a/libavfilter/Makefile
> +++ b/libavfilter/Makefile
> @@ -36,6 +36,7 @@ OBJS-$(CONFIG_PIXDESCTEST_FILTER) ? ? ? ? ? ?+= vf_pixdesctest.o
> ?OBJS-$(CONFIG_PIXELASPECT_FILTER) ? ? ? ? ? ?+= vf_aspect.o
> ?OBJS-$(CONFIG_SCALE_FILTER) ? ? ? ? ? ? ? ? ?+= vf_scale.o
> ?OBJS-$(CONFIG_SETTB_FILTER) ? ? ? ? ? ? ? ? ?+= vf_settb.o
> +OBJS-$(CONFIG_SETPTS_FILTER) ? ? ? ? ? ? ? ? += vf_setpts.o
> ?OBJS-$(CONFIG_SLICIFY_FILTER) ? ? ? ? ? ? ? ?+= vf_slicify.o
> ?OBJS-$(CONFIG_UNSHARP_FILTER) ? ? ? ? ? ? ? ?+= vf_unsharp.o
> ?OBJS-$(CONFIG_VFLIP_FILTER) ? ? ? ? ? ? ? ? ?+= vf_vflip.o
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index f5cc029..c00160f 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -56,6 +56,7 @@ void avfilter_register_all(void)
> ? ? REGISTER_FILTER (PIXELASPECT, pixelaspect, vf);
> ? ? REGISTER_FILTER (SCALE, ? ? ? scale, ? ? ? vf);
> ? ? REGISTER_FILTER (SETTB, ? ? ? settb, ? ? ? vf);
> + ? ?REGISTER_FILTER (SETPTS, ? ? ?setpts, ? ? ?vf);
> ? ? REGISTER_FILTER (SLICIFY, ? ? slicify, ? ? vf);
> ? ? REGISTER_FILTER (UNSHARP, ? ? unsharp, ? ? vf);
> ? ? REGISTER_FILTER (VFLIP, ? ? ? vflip, ? ? ? vf);
> diff --git a/libavfilter/vf_setpts.c b/libavfilter/vf_setpts.c
> new file mode 100644
> index 0000000..529325a
> --- /dev/null
> +++ b/libavfilter/vf_setpts.c
> @@ -0,0 +1,143 @@
> +/*
> + * copyright (c) 2008 Victor Paesa
> + *
> + * 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 presentation timestamp (PTS) modification filter
> + *
> + * @todo Add multiple inputs/outputs to filter
> + * @todo Add functions of pin number: pts(), startpts()
> + */
> +
> +#include "libavutil/eval.h"
> +#include "avfilter.h"
> +
> +static const char *const_names[] = {
> + ? ?"AVTB", ? ? ? ///< AV_TIME_BASE
> + ? ?"E", ? ? ? ? ?///< Euler number
> + ? ?"INTERLACED" ?///< tell if the current frame is interlaced
> + ? ?"N", ? ? ? ? ?///< frame number (starting at zero)
> + ? ?"NOPTS" ? ? ? ///< value corresponding to an undefined PTS
> + ? ?"PI", ? ? ? ? ///< greek pi
> + ? ?"POS", ? ? ? ?///< original position in the file of the frame
> + ? ?"PREV_INPTS" ?///< previous ?input PTS
> + ? ?"PREV_OUTPTS" ///< previous output PTS
> + ? ?"PTS", ? ? ? ?///< original pts in the file of the frame
> + ? ?"START_PTS", ?///< PTS at start of movie
> + ? ?NULL
> +};
> +
> +enum ConstName {
> + ? ?AVTB,
> + ? ?E,
> + ? ?INTERLACED,
> + ? ?N,
> + ? ?NOPTS,
> + ? ?PI,
> + ? ?POS,
> + ? ?PREV_INPTS,
> + ? ?PREV_OUTPTS,
> + ? ?PTS,
> + ? ?START_PTS,
> + ? ?CONSTS_NB
> +};
> +
> +typedef struct {
> + ? ?AVExpr *expr;
> + ? ?double const_values[CONSTS_NB];
> +} SetPTSContext;
> +
> +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
> +{
> + ? ?SetPTSContext *setpts = ctx->priv;
> + ? ?int ret;
> +
> + ? ?ret = av_parse_expr(&setpts->expr, args ? args : "PTS",
> + ? ? ? ? ? ? ? ? ? ? ? ?const_names, NULL, NULL, NULL, NULL, 0, ctx);
> + ? ?if (ret < 0) {
> + ? ? ? ?av_log(ctx, AV_LOG_ERROR,
> + ? ? ? ? ? ? ? "Error while parsing expression '%s'\n", args);
> + ? ? ? ?return ret;
> + ? ?}
> +
> + ? ?setpts->const_values[AVTB ? ? ? ] = AV_TIME_BASE;
> + ? ?setpts->const_values[E ? ? ? ? ?] = M_E;
> + ? ?setpts->const_values[N ? ? ? ? ?] = 0.0;
> + ? ?setpts->const_values[NOPTS ? ? ?] = AV_NOPTS_VALUE;
> + ? ?setpts->const_values[PI ? ? ? ? ] = M_PI;
> + ? ?setpts->const_values[PREV_INPTS ] = AV_NOPTS_VALUE;
> + ? ?setpts->const_values[PREV_OUTPTS] = AV_NOPTS_VALUE;
> + ? ?setpts->const_values[START_PTS ?] = AV_NOPTS_VALUE;
> + ? ?return 0;
> +}
> +
> +static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int w, int h)
> +{
> + ? ?return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h);
> +}
> +
> +static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
> +{
> + ? ?SetPTSContext *setpts = link->dst->priv;
> + ? ?AVFilterBufferRef *picref2 = avfilter_ref_buffer(picref, ~0);
> +
> + ? ?if (setpts->const_values[START_PTS] == AV_NOPTS_VALUE)
> + ? ? ? ?setpts->const_values[START_PTS] = picref2->pts;
> +
> + ? ?setpts->const_values[INTERLACED] = picref2->video->interlaced;
> + ? ?setpts->const_values[PTS ? ? ? ] = picref2->pts;
> +
> + ? ?picref2->pts = (int64_t)av_eval_expr(setpts->expr, setpts->const_values, setpts);
> + ? ?av_log(link->dst, AV_LOG_DEBUG, "n:%"PRId64" pts:%"PRId64" -> pts:%"PRId64"\n",
> + ? ? ? ? ? (int64_t)setpts->const_values[N ?],
> + ? ? ? ? ? (int64_t)setpts->const_values[PTS],
> + ? ? ? ? ? picref2->pts);
> +
> + ? ?setpts->const_values[N] += 1.0;
> + ? ?setpts->const_values[PREV_INPTS ] = (int64_t)picref ->pts;
> + ? ?setpts->const_values[PREV_OUTPTS] = (int64_t)picref2->pts;
> + ? ?avfilter_start_frame(link->dst->outputs[0], picref2);
> +}
> +
> +static av_cold void uninit(AVFilterContext *ctx)
> +{
> + ? ?SetPTSContext *setpts = ctx->priv;
> + ? ?av_free_expr(setpts->expr);
> + ? ?setpts->expr = NULL;
> +}
> +
> +AVFilter avfilter_vf_setpts = {
> + ? ?.name ? ? ?= "setpts",
> + ? ?.description = NULL_IF_CONFIG_SMALL("Set PTS for the output video frame."),
> + ? ?.init ? ? ?= init,
> + ? ?.uninit ? ?= uninit,
> +
> + ? ?.priv_size = sizeof(SetPTSContext),
> +
> + ? ?.inputs ? ?= (AVFilterPad[]) {{ .name ? ? ? ? ? ?= "default",
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?.type ? ? ? ? ? ?= AVMEDIA_TYPE_VIDEO,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?.get_video_buffer= get_video_buffer,
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?.start_frame ? ? = start_frame, },
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ .name = NULL }},
> + ? ?.outputs ? = (AVFilterPad[]) {{ .name ? ? ? ? ? ?= "default",
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?.type ? ? ? ? ? ?= AVMEDIA_TYPE_VIDEO, },
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?{ .name = NULL}},
> +};

Regards,
V?ctor



More information about the ffmpeg-devel mailing list