[FFmpeg-devel] [PATCH] vf_overlay: Add `timebase` option to set the time base source for the output video.
Vittorio Gambaletta (VittGam)
ffmpeg-dev at vittgam.net
Wed Jan 20 19:12:50 CET 2016
With this commit it is possible to use vf_overlay to center a video over
a black background, without having to know the video framerate in advance
and set it as parameter to lavfi.
Signed-off-by: Vittorio Gambaletta <ffmpeg-dev at vittgam.net>
---
doc/filters.texi | 14 ++++++++++++++
libavfilter/vf_overlay.c | 14 +++++++++-----
2 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/doc/filters.texi b/doc/filters.texi
index f5f4bfc..e12f476 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -8646,6 +8646,20 @@ main input until the end of the stream. A value of 0 disables this
behavior. Default value is 1.
@end table
+ at item timebase
+Set the time base source for the output video.
+
+It accepts the following values:
+ at table @samp
+ at item main
+use main input as time base source
+
+ at item overlay
+use overlay input as time base source
+ at end table
+
+Default value is @samp{main}.
+
The @option{x}, and @option{y} expressions can contain the following
parameters.
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index 3eac7f0..c6cd4ce 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -119,6 +119,7 @@ typedef struct OverlayContext {
uint8_t overlay_has_alpha;
int format; ///< OverlayFormat
int eval_mode; ///< EvalMode
+ int time_base; ///< MAIN or OVERLAY
FFDualInputContext dinput;
@@ -379,7 +380,7 @@ static int config_output(AVFilterLink *outlink)
outlink->w = ctx->inputs[MAIN]->w;
outlink->h = ctx->inputs[MAIN]->h;
- outlink->time_base = ctx->inputs[MAIN]->time_base;
+ outlink->time_base = ctx->inputs[s->time_base]->time_base;
return 0;
}
@@ -589,14 +590,14 @@ static AVFrame *do_blend(AVFilterContext *ctx, AVFrame *mainpic,
const AVFrame *second)
{
OverlayContext *s = ctx->priv;
- AVFilterLink *inlink = ctx->inputs[0];
if (s->eval_mode == EVAL_MODE_FRAME) {
- int64_t pos = av_frame_get_pkt_pos(mainpic);
+ AVFilterLink *inlink = ctx->inputs[s->time_base];
+ int64_t pts = s->time_base ? second->pts : mainpic->pts;
+ int64_t pos = av_frame_get_pkt_pos(s->time_base ? second : mainpic);
s->var_values[VAR_N] = inlink->frame_count;
- s->var_values[VAR_T] = mainpic->pts == AV_NOPTS_VALUE ?
- NAN : mainpic->pts * av_q2d(inlink->time_base);
+ s->var_values[VAR_T] = pts == AV_NOPTS_VALUE ? NAN : pts * av_q2d(inlink->time_base);
s->var_values[VAR_POS] = pos == -1 ? NAN : pos;
s->var_values[VAR_OVERLAY_W] = s->var_values[VAR_OW] = second->width;
@@ -673,6 +674,9 @@ static const AVOption overlay_options[] = {
{ "yuv444", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV444}, .flags = FLAGS, .unit = "format" },
{ "rgb", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_RGB}, .flags = FLAGS, .unit = "format" },
{ "repeatlast", "repeat overlay of the last overlay frame", OFFSET(dinput.repeatlast), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
+ { "timebase", "set time base source", OFFSET(time_base), AV_OPT_TYPE_INT, {.i64 = MAIN}, MAIN, OVERLAY, FLAGS, "timebase" },
+ { "main", "use main input as time base source", 0, AV_OPT_TYPE_CONST, {.i64=MAIN}, .flags = FLAGS, .unit = "timebase" },
+ { "overlay", "use overlay input as time base source", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY}, .flags = FLAGS, .unit = "timebase" },
{ NULL }
};
More information about the ffmpeg-devel
mailing list