[FFmpeg-cvslog] avfilter/vsrc_gradients: add duration option

Paul B Mahol git at videolan.org
Mon Aug 31 12:10:25 EEST 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Aug 31 10:46:42 2020 +0200| [64e93025f002c137c6b8baa8c7112482ce5df857] | committer: Paul B Mahol

avfilter/vsrc_gradients: add duration option

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=64e93025f002c137c6b8baa8c7112482ce5df857
---

 doc/filters.texi             |  8 ++++++++
 libavfilter/vsrc_gradients.c | 12 +++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index b0cdf92845..40d493fcae 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -22569,6 +22569,14 @@ Set number of colors to use at once. Allowed range is from 2 to 8. Default value
 
 @item seed
 Set seed for picking gradient line points.
+
+ at item duration, d
+Set the duration of the sourced video. See
+ at ref{time duration syntax,,the Time duration section in the ffmpeg-utils(1) manual,ffmpeg-utils}
+for the accepted syntax.
+
+If not specified, or the expressed duration is negative, the video is
+supposed to be generated forever.
 @end table
 
 
diff --git a/libavfilter/vsrc_gradients.c b/libavfilter/vsrc_gradients.c
index 984227017e..410c3cb69b 100644
--- a/libavfilter/vsrc_gradients.c
+++ b/libavfilter/vsrc_gradients.c
@@ -36,7 +36,8 @@ typedef struct GradientsContext {
     int w, h;
     int type;
     AVRational frame_rate;
-    uint64_t pts;
+    int64_t pts;
+    int64_t duration;           ///< duration expressed in microseconds
 
     uint8_t color_rgba[8][4];
     int nb_colors;
@@ -72,6 +73,8 @@ static const AVOption gradients_options[] = {
     {"nb_colors", "set the number of colors", OFFSET(nb_colors), AV_OPT_TYPE_INT,  {.i64=2},          2, 8, FLAGS },
     {"n",         "set the number of colors", OFFSET(nb_colors), AV_OPT_TYPE_INT,  {.i64=2},          2, 8, FLAGS },
     {"seed",      "set the seed",   OFFSET(seed),          AV_OPT_TYPE_INT64,      {.i64=-1},        -1, UINT32_MAX, FLAGS },
+    {"duration",  "set video duration", OFFSET(duration),  AV_OPT_TYPE_DURATION,   {.i64=-1},        -1, INT64_MAX, FLAGS },\
+    {"d",         "set video duration", OFFSET(duration),  AV_OPT_TYPE_DURATION,   {.i64=-1},        -1, INT64_MAX, FLAGS },\
     {NULL},
 };
 
@@ -251,6 +254,10 @@ static int gradients_request_frame(AVFilterLink *outlink)
     const float w2 = s->w / 2.f;
     const float h2 = s->h / 2.f;
 
+    if (s->duration >= 0 &&
+        av_rescale_q(s->pts, outlink->time_base, AV_TIME_BASE_Q) >= s->duration)
+        return AVERROR_EOF;
+
     s->fx0 = (s->x0 - w2) * cosf(angle) - (s->y0 - h2) * sinf(angle) + w2;
     s->fy0 = (s->x0 - w2) * sinf(angle) + (s->y0 - h2) * cosf(angle) + h2;
 
@@ -260,6 +267,9 @@ static int gradients_request_frame(AVFilterLink *outlink)
     if (!frame)
         return AVERROR(ENOMEM);
 
+    frame->key_frame           = 1;
+    frame->interlaced_frame    = 0;
+    frame->pict_type           = AV_PICTURE_TYPE_I;
     frame->sample_aspect_ratio = (AVRational) {1, 1};
     frame->pts = s->pts++;
 



More information about the ffmpeg-cvslog mailing list