[FFmpeg-devel] [PATCH 3/7] lavfi/tile: add nb_frames option.

Clément Bœsch ubitux at gmail.com
Thu Nov 8 23:44:08 CET 2012


---
 libavfilter/vf_tile.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_tile.c b/libavfilter/vf_tile.c
index 8f5a4f3..8cb68ea 100644
--- a/libavfilter/vf_tile.c
+++ b/libavfilter/vf_tile.c
@@ -37,6 +37,7 @@ typedef struct {
     unsigned margin;
     unsigned padding;
     unsigned current;
+    unsigned nb_frames;
     FFDrawContext draw;
     FFDrawColor blank;
 } TileContext;
@@ -51,6 +52,7 @@ static const AVOption tile_options[] = {
     { "s",    "set tile size", OFFSET(w), AV_OPT_TYPE_IMAGE_SIZE, {.str = "6x5"}, 0, 0, FLAGS },
     { "margin",  "set outer border margin in pixels",    OFFSET(margin),  AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1024, FLAGS },
     { "padding", "set inner border thickness in pixels", OFFSET(padding), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1024, FLAGS },
+    { "nb_frames", "set maximum number of frame to render", OFFSET(nb_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, FLAGS },
     {NULL},
 };
 
@@ -73,6 +75,15 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
                tile->w, tile->h);
         return AVERROR(EINVAL);
     }
+
+    if (tile->nb_frames == 0) {
+        tile->nb_frames = tile->w * tile->h;
+    } else if (tile->nb_frames > tile->w * tile->h) {
+        av_log(ctx, AV_LOG_ERROR, "nb_frames must be inferior to %dx%d=%d\n",
+               tile->w, tile->h, tile->w * tile->h);
+        return AVERROR(EINVAL);
+    }
+
     return 0;
 }
 
@@ -104,7 +115,7 @@ static int config_props(AVFilterLink *outlink)
     outlink->h = tile->h * inlink->h + th_pad_margins;
     outlink->sample_aspect_ratio = inlink->sample_aspect_ratio;
     outlink->frame_rate = av_mul_q(inlink->frame_rate,
-                                   (AVRational){ 1, tile->w * tile->h });
+                                   (AVRational){ 1, tile->nb_frames });
     ff_draw_init(&tile->draw, inlink->format, 0);
     /* TODO make the color an option, or find an unified way of choosing it */
     ff_draw_color(&tile->draw, &tile->blank, (uint8_t[]){ 0, 0, 0, -1 });
@@ -185,7 +196,7 @@ static void end_last_frame(AVFilterContext *ctx)
 
     outlink->out_buf = NULL;
     ff_start_frame(outlink, out_buf);
-    while (tile->current < tile->w * tile->h)
+    while (tile->current < tile->nb_frames)
         draw_blank_frame(ctx, out_buf);
     ff_draw_slice(outlink, 0, out_buf->video->h, 1);
     ff_end_frame(outlink);
@@ -198,7 +209,7 @@ static int end_frame(AVFilterLink *inlink)
     TileContext *tile    = ctx->priv;
 
     avfilter_unref_bufferp(&inlink->cur_buf);
-    if (++tile->current == tile->w * tile->h)
+    if (++tile->current == tile->nb_frames)
         end_last_frame(ctx);
     return 0;
 }
-- 
1.8.0



More information about the ffmpeg-devel mailing list