[FFmpeg-devel] [PATCH] lavfi/overlay: implement shortest option

Stefano Sabatini stefasab at gmail.com
Mon Feb 18 23:13:46 CET 2013


Force termination when the overlay stream ends. Simplify scripting logic,
for example when an infinite source is used to generate a background for
a composite video.

TODO: bump micro
---
 doc/filters.texi         |   16 ++++++++++++++++
 libavfilter/vf_overlay.c |    4 ++++
 2 files changed, 20 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index a9ee7cb..d777875 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -3873,6 +3873,10 @@ same as @var{overlay_w} and @var{overlay_h}
 @item rgb
 If set to 1, force the filter to accept inputs in the RGB
 color space. Default value is 0.
+
+ at item shortest
+If set to 1, force the output to terminate when the shortest input
+terminates. Default value is 0.
 @end table
 
 Be aware that frames are taken from each input video in timestamp
@@ -3933,6 +3937,18 @@ ffplay input.avi -vf 'split[b], pad=iw*2[src], [b]deshake, [src]overlay=w'
 @end example
 
 @item
+Create a side by side video, combining left and right videos side to side:
+ at example
+ffmpeg -i left.avi -i right.avi -filter_complex "
+nullsrc=size=200x100 [background];
+[0:v] setpts=PTS-STARTPTS, scale=100x100 [left];
+[1:v] setpts=PTS-STARTPTS, scale=100x100 [right];
+[background][left]       overlay=shortest=1       [background+left];
+[background+left][right] overlay=shortest=1:x=100 [left+right]
+"
+ at end example
+
+ at item
 Chain several overlays in cascade:
 @example
 nullsrc=s=200x200 [bg];
diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c
index d44677f..b3fc869 100644
--- a/libavfilter/vf_overlay.c
+++ b/libavfilter/vf_overlay.c
@@ -91,6 +91,7 @@ typedef struct {
     int main_pix_step[4];       ///< steps per pixel for each plane of the main output
     int overlay_pix_step[4];    ///< steps per pixel for each plane of the overlay
     int hsub, vsub;             ///< chroma subsampling values
+    int shortest;               ///< terminate stream when the shortest input terminates
 
     char *x_expr, *y_expr;
 } OverlayContext;
@@ -102,6 +103,7 @@ static const AVOption overlay_options[] = {
     { "x", "set the x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
     { "y", "set the y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX, FLAGS },
     {"rgb", "force packed RGB in input and output", OFFSET(allow_packed_rgb), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS },
+    { "shortest", "force termination when the shortest input terminates", OFFSET(shortest), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
     {NULL},
 };
 
@@ -552,6 +554,8 @@ static int request_frame(AVFilterLink *outlink)
         /* EOF on main is reported immediately */
         if (ret == AVERROR_EOF && input == OVERLAY) {
             over->overlay_eof = 1;
+            if (over->shortest)
+                return ret;
             if ((ret = try_filter_next_frame(ctx)) != AVERROR(EAGAIN))
                 return ret;
             ret = 0; /* continue requesting frames on main */
-- 
1.7.9.5



More information about the ffmpeg-devel mailing list