I have a webcam that outputs raw MJPEG over HTTP and for which I need
to create timestamps in order to properly avplay or avconv the stream.
Thus I extended vf_setpts to allow to get the current wallclock time and
use that as a timestamp with:
setpts='(GETTIME - STARTTIME) / (TB * 1000000)"
>From 7adfbdff0cb1d529364254ec4b242e89cfa753ec Mon Sep 17 00:00:00 2001
From: Vladimir Pantelic <[email protected]>
Date: Wed, 23 Jan 2013 13:54:08 +0100
Subject: [PATCH] avfilter: allow setpts filter to use wallclock time for
calculations
Signed-off-by: Vladimir Pantelic <[email protected]>
---
doc/filters.texi | 9 +++++++++
libavfilter/vf_setpts.c | 7 +++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index 34db2f4..ff9764c 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1864,6 +1864,12 @@ previous input PTS
@item PREV_OUTPTS
previous output PTS
+@item GETTIME
+current time in us
+
+@item STARTTIME
+current time at the start of the movie in us
+
@end table
Some examples follow:
@@ -1883,6 +1889,9 @@ setpts=N/(25*TB)
# fixed rate 25 fps with some jitter
setpts='1/(25*TB) * (N + 0.05 * sin(N*2*PI/25))'
+
+# generate timestamps from a "live source" and rebase onto the current timebase
+setpts='(GETTIME - STARTTIME) / (TB * 1000000)"
@end example
@anchor{setsar}
diff --git a/libavfilter/vf_setpts.c b/libavfilter/vf_setpts.c
index 0c4881e..74dc583 100644
--- a/libavfilter/vf_setpts.c
+++ b/libavfilter/vf_setpts.c
@@ -29,6 +29,7 @@
#include "libavutil/eval.h"
#include "libavutil/internal.h"
#include "libavutil/mathematics.h"
+#include "libavutil/time.h"
#include "avfilter.h"
#include "internal.h"
#include "video.h"
@@ -45,6 +46,8 @@ static const char *const var_names[] = {
"PTS", ///< original pts in the file of the frame
"STARTPTS", ///< PTS at start of movie
"TB", ///< timebase
+ "GETTIME", ///< current time in us
+ "STARTTIME", ///< current time at the start of the movie in us
NULL
};
@@ -60,6 +63,8 @@ enum var_name {
VAR_PTS,
VAR_STARTPTS,
VAR_TB,
+ VAR_GETTIME,
+ VAR_STARTTIME,
VAR_VARS_NB
};
@@ -94,6 +99,7 @@ static int config_input(AVFilterLink *inlink)
SetPTSContext *setpts = inlink->dst->priv;
setpts->var_values[VAR_TB] = av_q2d(inlink->time_base);
+ setpts->var_values[VAR_STARTTIME] = av_gettime();
av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f\n", setpts->var_values[VAR_TB]);
return 0;
@@ -114,6 +120,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
setpts->var_values[VAR_INTERLACED] = frame->video->interlaced;
setpts->var_values[VAR_PTS ] = TS2D(frame->pts);
setpts->var_values[VAR_POS ] = frame->pos == -1 ? NAN : frame->pos;
+ setpts->var_values[VAR_GETTIME ] = av_gettime();
d = av_expr_eval(setpts->expr, setpts->var_values, NULL);
frame->pts = D2TS(d);
--
1.7.6.rc1.1.g2c162b
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel