Commit 0b55b16a authored by Vladimir Pantelic's avatar Vladimir Pantelic Committed by Luca Barbato

avfilter: allow setpts filter to use wallclock time for calculations

Signed-off-by: 's avatarVladimir Pantelic <vladoman@gmail.com>
Signed-off-by: 's avatarLuca Barbato <lu_zero@gentoo.org>
parent b85a5e87
...@@ -1864,6 +1864,12 @@ previous input PTS ...@@ -1864,6 +1864,12 @@ previous input PTS
@item PREV_OUTPTS @item PREV_OUTPTS
previous output PTS previous output PTS
@item RTCTIME
wallclock (RTC) time in microseconds
@item RTCSTART
wallclock (RTC) time at the start of the movie in microseconds
@end table @end table
Some examples follow: Some examples follow:
...@@ -1883,6 +1889,9 @@ setpts=N/(25*TB) ...@@ -1883,6 +1889,9 @@ setpts=N/(25*TB)
# fixed rate 25 fps with some jitter # fixed rate 25 fps with some jitter
setpts='1/(25*TB) * (N + 0.05 * sin(N*2*PI/25))' 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='(RTCTIME - RTCSTART) / (TB * 1000000)"
@end example @end example
@anchor{setsar} @anchor{setsar}
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "libavutil/eval.h" #include "libavutil/eval.h"
#include "libavutil/internal.h" #include "libavutil/internal.h"
#include "libavutil/mathematics.h" #include "libavutil/mathematics.h"
#include "libavutil/time.h"
#include "avfilter.h" #include "avfilter.h"
#include "internal.h" #include "internal.h"
#include "video.h" #include "video.h"
...@@ -45,6 +46,8 @@ static const char *const var_names[] = { ...@@ -45,6 +46,8 @@ static const char *const var_names[] = {
"PTS", ///< original pts in the file of the frame "PTS", ///< original pts in the file of the frame
"STARTPTS", ///< PTS at start of movie "STARTPTS", ///< PTS at start of movie
"TB", ///< timebase "TB", ///< timebase
"RTCTIME", ///< wallclock (RTC) time in micro seconds
"RTCSTART", ///< wallclock (RTC) time at the start of the movie in micro seconds
NULL NULL
}; };
...@@ -60,6 +63,8 @@ enum var_name { ...@@ -60,6 +63,8 @@ enum var_name {
VAR_PTS, VAR_PTS,
VAR_STARTPTS, VAR_STARTPTS,
VAR_TB, VAR_TB,
VAR_RTCTIME,
VAR_RTCSTART,
VAR_VARS_NB VAR_VARS_NB
}; };
...@@ -94,6 +99,7 @@ static int config_input(AVFilterLink *inlink) ...@@ -94,6 +99,7 @@ static int config_input(AVFilterLink *inlink)
SetPTSContext *setpts = inlink->dst->priv; SetPTSContext *setpts = inlink->dst->priv;
setpts->var_values[VAR_TB] = av_q2d(inlink->time_base); setpts->var_values[VAR_TB] = av_q2d(inlink->time_base);
setpts->var_values[VAR_RTCSTART] = av_gettime();
av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f\n", setpts->var_values[VAR_TB]); av_log(inlink->src, AV_LOG_VERBOSE, "TB:%f\n", setpts->var_values[VAR_TB]);
return 0; return 0;
...@@ -114,6 +120,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame) ...@@ -114,6 +120,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *frame)
setpts->var_values[VAR_INTERLACED] = frame->video->interlaced; setpts->var_values[VAR_INTERLACED] = frame->video->interlaced;
setpts->var_values[VAR_PTS ] = TS2D(frame->pts); setpts->var_values[VAR_PTS ] = TS2D(frame->pts);
setpts->var_values[VAR_POS ] = frame->pos == -1 ? NAN : frame->pos; setpts->var_values[VAR_POS ] = frame->pos == -1 ? NAN : frame->pos;
setpts->var_values[VAR_RTCTIME ] = av_gettime();
d = av_expr_eval(setpts->expr, setpts->var_values, NULL); d = av_expr_eval(setpts->expr, setpts->var_values, NULL);
frame->pts = D2TS(d); frame->pts = D2TS(d);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment