Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode
@ 2023-04-19 10:42 Marvin Scholz
  2023-04-19 10:42 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Marvin Scholz @ 2023-04-19 10:42 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz

---
 libavfilter/vf_tpad.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
index f0c065f0c3..88c3c99de4 100644
--- a/libavfilter/vf_tpad.c
+++ b/libavfilter/vf_tpad.c
@@ -27,6 +27,12 @@
 #include "formats.h"
 #include "drawutils.h"
 
+enum PadMode {
+    MODE_ADD = 0,
+    MODE_CLONE,
+    NB_MODE
+};
+
 typedef struct TPadContext {
     const AVClass *class;
     int pad_start;
@@ -51,10 +57,10 @@ typedef struct TPadContext {
 static const AVOption tpad_options[] = {
     { "start", "set the number of frames to delay input",              OFFSET(pad_start),  AV_OPT_TYPE_INT,   {.i64=0},        0,   INT_MAX, VF },
     { "stop",  "set the number of frames to add after input finished", OFFSET(pad_stop),   AV_OPT_TYPE_INT,   {.i64=0},       -1,   INT_MAX, VF },
-    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
-    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=0},        0,         0, VF, "mode" },
-    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=1},        0,         0, VF, "mode" },
-    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
+    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=MODE_ADD}, 0, NB_MODE-1, VF, "mode" },
+    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_ADD},   0,         0, VF, "mode" },
+    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_CLONE}, 0,         0, VF, "mode" },
+    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0, NB_MODE-1, VF, "mode" },
     { "start_duration", "set the duration to delay input",             OFFSET(start_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
     { "stop_duration",  "set the duration to pad input",               OFFSET(stop_duration),  AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
     { "color", "set the color of the added frames",                    OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="black"},  0,         0, VF },
@@ -91,7 +97,7 @@ static int activate(AVFilterContext *ctx)
         }
     }
 
-    if (s->start_mode == 0 && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
+    if (s->start_mode == MODE_ADD && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
         frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
         if (!frame)
             return AVERROR(ENOMEM);
@@ -106,7 +112,7 @@ static int activate(AVFilterContext *ctx)
         return ff_filter_frame(outlink, frame);
     }
 
-    if (s->start_mode == 1 && s->pad_start > 0) {
+    if (s->start_mode == MODE_CLONE && s->pad_start > 0) {
         if (s->eof) {
             ff_outlink_set_status(outlink, AVERROR_EOF, 0);
             return 0;
@@ -133,7 +139,7 @@ static int activate(AVFilterContext *ctx)
         if (ret < 0)
             return ret;
         if (ret > 0) {
-            if (s->stop_mode == 1 && s->pad_stop != 0) {
+            if (s->stop_mode == MODE_CLONE && s->pad_stop != 0) {
                 av_frame_free(&s->cache_stop);
                 s->cache_stop = av_frame_clone(frame);
             }
@@ -147,14 +153,14 @@ static int activate(AVFilterContext *ctx)
             ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
             return 0;
         }
-        if (s->stop_mode == 0) {
+        if (s->stop_mode == MODE_ADD) {
             frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
             if (!frame)
                 return AVERROR(ENOMEM);
             ff_fill_rectangle(&s->draw, &s->color,
                               frame->data, frame->linesize,
                               0, 0, frame->width, frame->height);
-        } else if (s->stop_mode == 1) {
+        } else if (s->stop_mode == MODE_CLONE) {
             if (!s->cache_stop) {
                 s->pad_stop = 0;
                 ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
-- 
2.37.0 (Apple Git-136)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode
  2023-04-19 10:42 [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
@ 2023-04-19 10:42 ` Marvin Scholz
  2023-04-19 10:45   ` Marvin Scholz
  2023-05-01 12:18 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
  2023-05-22 10:14 ` [FFmpeg-devel] [PATCH v3 " Marvin Scholz
  2 siblings, 1 reply; 10+ messages in thread
From: Marvin Scholz @ 2023-04-19 10:42 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz

When no drawing is to be performed, tpad can work fine with
hardware frames, so advertise this in the query_formats
callback and ensure the drawing context is never initialized
when just cloning frames.
---
 libavfilter/vf_tpad.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
index 88c3c99de4..9a9d06a8b8 100644
--- a/libavfilter/vf_tpad.c
+++ b/libavfilter/vf_tpad.c
@@ -71,7 +71,13 @@ AVFILTER_DEFINE_CLASS(tpad);
 
 static int query_formats(AVFilterContext *ctx)
 {
-    return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
+    TPadContext *s = ctx->priv;
+    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
+        (s->start_mode == MODE_ADD && s->pad_start != 0))
+        return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
+
+    fprintf(stderr, "ONLY COPY\n");
+    return ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_VIDEO));
 }
 
 static int activate(AVFilterContext *ctx)
@@ -190,8 +196,11 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     TPadContext *s = ctx->priv;
 
-    ff_draw_init(&s->draw, inlink->format, 0);
-    ff_draw_color(&s->draw, &s->color, s->rgba_color);
+    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
+        (s->start_mode == MODE_ADD && s->pad_start != 0)) {
+        ff_draw_init(&s->draw, inlink->format, 0);
+        ff_draw_color(&s->draw, &s->color, s->rgba_color);
+    }
 
     if (s->start_duration)
         s->pad_start = av_rescale_q(s->start_duration, inlink->frame_rate, av_inv_q(AV_TIME_BASE_Q));
-- 
2.37.0 (Apple Git-136)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode
  2023-04-19 10:42 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
@ 2023-04-19 10:45   ` Marvin Scholz
  0 siblings, 0 replies; 10+ messages in thread
From: Marvin Scholz @ 2023-04-19 10:45 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz



On 19 Apr 2023, at 12:42, Marvin Scholz wrote:

> When no drawing is to be performed, tpad can work fine with
> hardware frames, so advertise this in the query_formats
> callback and ensure the drawing context is never initialized
> when just cloning frames.
> ---
>  libavfilter/vf_tpad.c | 15 ++++++++++++---
>  1 file changed, 12 insertions(+), 3 deletions(-)
>
> diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
> index 88c3c99de4..9a9d06a8b8 100644
> --- a/libavfilter/vf_tpad.c
> +++ b/libavfilter/vf_tpad.c
> @@ -71,7 +71,13 @@ AVFILTER_DEFINE_CLASS(tpad);
>
>  static int query_formats(AVFilterContext *ctx)
>  {
> -    return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
> +    TPadContext *s = ctx->priv;
> +    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
> +        (s->start_mode == MODE_ADD && s->pad_start != 0))
> +        return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
> +
> +    fprintf(stderr, "ONLY COPY\n");

Apparently I am not fully awake yet and forgot to update the commit with the removal
of this debug output… Will obviously be removed in the next iteration.

> +    return ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_VIDEO));
>  }
>
>  static int activate(AVFilterContext *ctx)
> @@ -190,8 +196,11 @@ static int config_input(AVFilterLink *inlink)
>      AVFilterContext *ctx = inlink->dst;
>      TPadContext *s = ctx->priv;
>
> -    ff_draw_init(&s->draw, inlink->format, 0);
> -    ff_draw_color(&s->draw, &s->color, s->rgba_color);
> +    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
> +        (s->start_mode == MODE_ADD && s->pad_start != 0)) {
> +        ff_draw_init(&s->draw, inlink->format, 0);
> +        ff_draw_color(&s->draw, &s->color, s->rgba_color);
> +    }
>
>      if (s->start_duration)
>          s->pad_start = av_rescale_q(s->start_duration, inlink->frame_rate, av_inv_q(AV_TIME_BASE_Q));
> -- 
> 2.37.0 (Apple Git-136)
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode
  2023-04-19 10:42 [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
  2023-04-19 10:42 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
@ 2023-05-01 12:18 ` Marvin Scholz
  2023-05-01 12:18   ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
  2023-05-05 20:01   ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Thilo Borgmann
  2023-05-22 10:14 ` [FFmpeg-devel] [PATCH v3 " Marvin Scholz
  2 siblings, 2 replies; 10+ messages in thread
From: Marvin Scholz @ 2023-05-01 12:18 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz

---
 libavfilter/vf_tpad.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
index f0c065f0c3..88c3c99de4 100644
--- a/libavfilter/vf_tpad.c
+++ b/libavfilter/vf_tpad.c
@@ -27,6 +27,12 @@
 #include "formats.h"
 #include "drawutils.h"
 
+enum PadMode {
+    MODE_ADD = 0,
+    MODE_CLONE,
+    NB_MODE
+};
+
 typedef struct TPadContext {
     const AVClass *class;
     int pad_start;
@@ -51,10 +57,10 @@ typedef struct TPadContext {
 static const AVOption tpad_options[] = {
     { "start", "set the number of frames to delay input",              OFFSET(pad_start),  AV_OPT_TYPE_INT,   {.i64=0},        0,   INT_MAX, VF },
     { "stop",  "set the number of frames to add after input finished", OFFSET(pad_stop),   AV_OPT_TYPE_INT,   {.i64=0},       -1,   INT_MAX, VF },
-    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
-    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=0},        0,         0, VF, "mode" },
-    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=1},        0,         0, VF, "mode" },
-    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
+    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=MODE_ADD}, 0, NB_MODE-1, VF, "mode" },
+    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_ADD},   0,         0, VF, "mode" },
+    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_CLONE}, 0,         0, VF, "mode" },
+    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0, NB_MODE-1, VF, "mode" },
     { "start_duration", "set the duration to delay input",             OFFSET(start_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
     { "stop_duration",  "set the duration to pad input",               OFFSET(stop_duration),  AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
     { "color", "set the color of the added frames",                    OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="black"},  0,         0, VF },
@@ -91,7 +97,7 @@ static int activate(AVFilterContext *ctx)
         }
     }
 
-    if (s->start_mode == 0 && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
+    if (s->start_mode == MODE_ADD && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
         frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
         if (!frame)
             return AVERROR(ENOMEM);
@@ -106,7 +112,7 @@ static int activate(AVFilterContext *ctx)
         return ff_filter_frame(outlink, frame);
     }
 
-    if (s->start_mode == 1 && s->pad_start > 0) {
+    if (s->start_mode == MODE_CLONE && s->pad_start > 0) {
         if (s->eof) {
             ff_outlink_set_status(outlink, AVERROR_EOF, 0);
             return 0;
@@ -133,7 +139,7 @@ static int activate(AVFilterContext *ctx)
         if (ret < 0)
             return ret;
         if (ret > 0) {
-            if (s->stop_mode == 1 && s->pad_stop != 0) {
+            if (s->stop_mode == MODE_CLONE && s->pad_stop != 0) {
                 av_frame_free(&s->cache_stop);
                 s->cache_stop = av_frame_clone(frame);
             }
@@ -147,14 +153,14 @@ static int activate(AVFilterContext *ctx)
             ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
             return 0;
         }
-        if (s->stop_mode == 0) {
+        if (s->stop_mode == MODE_ADD) {
             frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
             if (!frame)
                 return AVERROR(ENOMEM);
             ff_fill_rectangle(&s->draw, &s->color,
                               frame->data, frame->linesize,
                               0, 0, frame->width, frame->height);
-        } else if (s->stop_mode == 1) {
+        } else if (s->stop_mode == MODE_CLONE) {
             if (!s->cache_stop) {
                 s->pad_stop = 0;
                 ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
-- 
2.37.0 (Apple Git-136)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode
  2023-05-01 12:18 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
@ 2023-05-01 12:18   ` Marvin Scholz
  2023-05-05 20:02     ` Thilo Borgmann
  2023-05-05 20:01   ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Thilo Borgmann
  1 sibling, 1 reply; 10+ messages in thread
From: Marvin Scholz @ 2023-05-01 12:18 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz

When no drawing is to be performed, tpad can work fine with
hardware frames, so advertise this in the query_formats
callback and ensure the drawing context is never initialised
when just cloning frames.
---
 libavfilter/vf_tpad.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
index 88c3c99de4..cabfe33685 100644
--- a/libavfilter/vf_tpad.c
+++ b/libavfilter/vf_tpad.c
@@ -71,7 +71,12 @@ AVFILTER_DEFINE_CLASS(tpad);
 
 static int query_formats(AVFilterContext *ctx)
 {
-    return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
+    TPadContext *s = ctx->priv;
+    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
+        (s->start_mode == MODE_ADD && s->pad_start != 0))
+        return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
+
+    return ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_VIDEO));
 }
 
 static int activate(AVFilterContext *ctx)
@@ -190,8 +195,11 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     TPadContext *s = ctx->priv;
 
-    ff_draw_init(&s->draw, inlink->format, 0);
-    ff_draw_color(&s->draw, &s->color, s->rgba_color);
+    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
+        (s->start_mode == MODE_ADD && s->pad_start != 0)) {
+        ff_draw_init(&s->draw, inlink->format, 0);
+        ff_draw_color(&s->draw, &s->color, s->rgba_color);
+    }
 
     if (s->start_duration)
         s->pad_start = av_rescale_q(s->start_duration, inlink->frame_rate, av_inv_q(AV_TIME_BASE_Q));
-- 
2.37.0 (Apple Git-136)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode
  2023-05-01 12:18 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
  2023-05-01 12:18   ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
@ 2023-05-05 20:01   ` Thilo Borgmann
  1 sibling, 0 replies; 10+ messages in thread
From: Thilo Borgmann @ 2023-05-05 20:01 UTC (permalink / raw)
  To: ffmpeg-devel

Hi,


Am 01.05.23 um 14:18 schrieb Marvin Scholz:
> ---
>   libavfilter/vf_tpad.c | 24 +++++++++++++++---------
>   1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
> index f0c065f0c3..88c3c99de4 100644
> --- a/libavfilter/vf_tpad.c
> +++ b/libavfilter/vf_tpad.c
> @@ -27,6 +27,12 @@
>   #include "formats.h"
>   #include "drawutils.h"
>   
> +enum PadMode {
> +    MODE_ADD = 0,
> +    MODE_CLONE,
> +    NB_MODE
> +};
> +
>   typedef struct TPadContext {
>       const AVClass *class;
>       int pad_start;
> @@ -51,10 +57,10 @@ typedef struct TPadContext {
>   static const AVOption tpad_options[] = {
>       { "start", "set the number of frames to delay input",              OFFSET(pad_start),  AV_OPT_TYPE_INT,   {.i64=0},        0,   INT_MAX, VF },
>       { "stop",  "set the number of frames to add after input finished", OFFSET(pad_stop),   AV_OPT_TYPE_INT,   {.i64=0},       -1,   INT_MAX, VF },
> -    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
> -    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=0},        0,         0, VF, "mode" },
> -    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=1},        0,         0, VF, "mode" },
> -    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
> +    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=MODE_ADD}, 0, NB_MODE-1, VF, "mode" },
> +    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_ADD},   0,         0, VF, "mode" },
> +    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_CLONE}, 0,         0, VF, "mode" },

> +    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0, NB_MODE-1, VF, "mode" },

I think you wanted to use MODE_ADD to init this as well.

Otherwise LGTM.

-Thilo
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode
  2023-05-01 12:18   ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
@ 2023-05-05 20:02     ` Thilo Borgmann
  0 siblings, 0 replies; 10+ messages in thread
From: Thilo Borgmann @ 2023-05-05 20:02 UTC (permalink / raw)
  To: ffmpeg-devel

Am 01.05.23 um 14:18 schrieb Marvin Scholz:
> When no drawing is to be performed, tpad can work fine with
> hardware frames, so advertise this in the query_formats
> callback and ensure the drawing context is never initialised
> when just cloning frames.
> ---
>   libavfilter/vf_tpad.c | 14 +++++++++++---
>   1 file changed, 11 insertions(+), 3 deletions(-)

LGTM if tested.

-Thilo

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH v3 1/2] avfilter/vf_tpad: use enum for start/stop_mode
  2023-04-19 10:42 [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
  2023-04-19 10:42 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
  2023-05-01 12:18 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
@ 2023-05-22 10:14 ` Marvin Scholz
  2023-05-22 10:14   ` [FFmpeg-devel] [PATCH v3 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
  2023-05-22 16:37   ` [FFmpeg-devel] [PATCH v3 1/2] avfilter/vf_tpad: use enum for start/stop_mode Niklas Haas
  2 siblings, 2 replies; 10+ messages in thread
From: Marvin Scholz @ 2023-05-22 10:14 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz

---
 libavfilter/vf_tpad.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
index f0c065f0c3..d0fa7df8be 100644
--- a/libavfilter/vf_tpad.c
+++ b/libavfilter/vf_tpad.c
@@ -27,6 +27,12 @@
 #include "formats.h"
 #include "drawutils.h"
 
+enum PadMode {
+    MODE_ADD = 0,
+    MODE_CLONE,
+    NB_MODE
+};
+
 typedef struct TPadContext {
     const AVClass *class;
     int pad_start;
@@ -51,10 +57,10 @@ typedef struct TPadContext {
 static const AVOption tpad_options[] = {
     { "start", "set the number of frames to delay input",              OFFSET(pad_start),  AV_OPT_TYPE_INT,   {.i64=0},        0,   INT_MAX, VF },
     { "stop",  "set the number of frames to add after input finished", OFFSET(pad_stop),   AV_OPT_TYPE_INT,   {.i64=0},       -1,   INT_MAX, VF },
-    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
-    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=0},        0,         0, VF, "mode" },
-    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=1},        0,         0, VF, "mode" },
-    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
+    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=MODE_ADD}, 0, NB_MODE-1, VF, "mode" },
+    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_ADD},   0,         0, VF, "mode" },
+    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_CLONE}, 0,         0, VF, "mode" },
+    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=MODE_ADD}, 0, NB_MODE-1, VF, "mode" },
     { "start_duration", "set the duration to delay input",             OFFSET(start_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
     { "stop_duration",  "set the duration to pad input",               OFFSET(stop_duration),  AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
     { "color", "set the color of the added frames",                    OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="black"},  0,         0, VF },
@@ -91,7 +97,7 @@ static int activate(AVFilterContext *ctx)
         }
     }
 
-    if (s->start_mode == 0 && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
+    if (s->start_mode == MODE_ADD && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
         frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
         if (!frame)
             return AVERROR(ENOMEM);
@@ -106,7 +112,7 @@ static int activate(AVFilterContext *ctx)
         return ff_filter_frame(outlink, frame);
     }
 
-    if (s->start_mode == 1 && s->pad_start > 0) {
+    if (s->start_mode == MODE_CLONE && s->pad_start > 0) {
         if (s->eof) {
             ff_outlink_set_status(outlink, AVERROR_EOF, 0);
             return 0;
@@ -133,7 +139,7 @@ static int activate(AVFilterContext *ctx)
         if (ret < 0)
             return ret;
         if (ret > 0) {
-            if (s->stop_mode == 1 && s->pad_stop != 0) {
+            if (s->stop_mode == MODE_CLONE && s->pad_stop != 0) {
                 av_frame_free(&s->cache_stop);
                 s->cache_stop = av_frame_clone(frame);
             }
@@ -147,14 +153,14 @@ static int activate(AVFilterContext *ctx)
             ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
             return 0;
         }
-        if (s->stop_mode == 0) {
+        if (s->stop_mode == MODE_ADD) {
             frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
             if (!frame)
                 return AVERROR(ENOMEM);
             ff_fill_rectangle(&s->draw, &s->color,
                               frame->data, frame->linesize,
                               0, 0, frame->width, frame->height);
-        } else if (s->stop_mode == 1) {
+        } else if (s->stop_mode == MODE_CLONE) {
             if (!s->cache_stop) {
                 s->pad_stop = 0;
                 ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
-- 
2.37.0 (Apple Git-136)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [FFmpeg-devel] [PATCH v3 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode
  2023-05-22 10:14 ` [FFmpeg-devel] [PATCH v3 " Marvin Scholz
@ 2023-05-22 10:14   ` Marvin Scholz
  2023-05-22 16:37   ` [FFmpeg-devel] [PATCH v3 1/2] avfilter/vf_tpad: use enum for start/stop_mode Niklas Haas
  1 sibling, 0 replies; 10+ messages in thread
From: Marvin Scholz @ 2023-05-22 10:14 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz

When no drawing is to be performed, tpad can work fine with
hardware frames, so advertise this in the query_formats
callback and ensure the drawing context is never initialised
when just cloning frames.
---
 libavfilter/vf_tpad.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
index d0fa7df8be..c2e266cb1a 100644
--- a/libavfilter/vf_tpad.c
+++ b/libavfilter/vf_tpad.c
@@ -71,7 +71,12 @@ AVFILTER_DEFINE_CLASS(tpad);
 
 static int query_formats(AVFilterContext *ctx)
 {
-    return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
+    TPadContext *s = ctx->priv;
+    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
+        (s->start_mode == MODE_ADD && s->pad_start != 0))
+        return ff_set_common_formats(ctx, ff_draw_supported_pixel_formats(0));
+
+    return ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_VIDEO));
 }
 
 static int activate(AVFilterContext *ctx)
@@ -190,8 +195,11 @@ static int config_input(AVFilterLink *inlink)
     AVFilterContext *ctx = inlink->dst;
     TPadContext *s = ctx->priv;
 
-    ff_draw_init(&s->draw, inlink->format, 0);
-    ff_draw_color(&s->draw, &s->color, s->rgba_color);
+    if ((s->stop_mode == MODE_ADD && s->pad_stop != 0) ||
+        (s->start_mode == MODE_ADD && s->pad_start != 0)) {
+        ff_draw_init(&s->draw, inlink->format, 0);
+        ff_draw_color(&s->draw, &s->color, s->rgba_color);
+    }
 
     if (s->start_duration)
         s->pad_start = av_rescale_q(s->start_duration, inlink->frame_rate, av_inv_q(AV_TIME_BASE_Q));
-- 
2.37.0 (Apple Git-136)

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [FFmpeg-devel] [PATCH v3 1/2] avfilter/vf_tpad: use enum for start/stop_mode
  2023-05-22 10:14 ` [FFmpeg-devel] [PATCH v3 " Marvin Scholz
  2023-05-22 10:14   ` [FFmpeg-devel] [PATCH v3 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
@ 2023-05-22 16:37   ` Niklas Haas
  1 sibling, 0 replies; 10+ messages in thread
From: Niklas Haas @ 2023-05-22 16:37 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Marvin Scholz

On Mon, 22 May 2023 12:14:32 +0200 Marvin Scholz <epirat07@gmail.com> wrote:
> ---
>  libavfilter/vf_tpad.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c
> index f0c065f0c3..d0fa7df8be 100644
> --- a/libavfilter/vf_tpad.c
> +++ b/libavfilter/vf_tpad.c
> @@ -27,6 +27,12 @@
>  #include "formats.h"
>  #include "drawutils.h"
>  
> +enum PadMode {
> +    MODE_ADD = 0,
> +    MODE_CLONE,
> +    NB_MODE
> +};
> +
>  typedef struct TPadContext {
>      const AVClass *class;
>      int pad_start;
> @@ -51,10 +57,10 @@ typedef struct TPadContext {
>  static const AVOption tpad_options[] = {
>      { "start", "set the number of frames to delay input",              OFFSET(pad_start),  AV_OPT_TYPE_INT,   {.i64=0},        0,   INT_MAX, VF },
>      { "stop",  "set the number of frames to add after input finished", OFFSET(pad_stop),   AV_OPT_TYPE_INT,   {.i64=0},       -1,   INT_MAX, VF },
> -    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
> -    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=0},        0,         0, VF, "mode" },
> -    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=1},        0,         0, VF, "mode" },
> -    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=0},        0,         1, VF, "mode" },
> +    { "start_mode", "set the mode of added frames to start",           OFFSET(start_mode), AV_OPT_TYPE_INT,   {.i64=MODE_ADD}, 0, NB_MODE-1, VF, "mode" },
> +    { "add",   "add solid-color frames",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_ADD},   0,         0, VF, "mode" },
> +    { "clone", "clone first/last frame",                               0,                  AV_OPT_TYPE_CONST, {.i64=MODE_CLONE}, 0,         0, VF, "mode" },
> +    { "stop_mode",  "set the mode of added frames to end",             OFFSET(stop_mode),  AV_OPT_TYPE_INT,   {.i64=MODE_ADD}, 0, NB_MODE-1, VF, "mode" },
>      { "start_duration", "set the duration to delay input",             OFFSET(start_duration), AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
>      { "stop_duration",  "set the duration to pad input",               OFFSET(stop_duration),  AV_OPT_TYPE_DURATION, {.i64=0}, 0, INT64_MAX, VF },
>      { "color", "set the color of the added frames",                    OFFSET(rgba_color), AV_OPT_TYPE_COLOR, {.str="black"},  0,         0, VF },
> @@ -91,7 +97,7 @@ static int activate(AVFilterContext *ctx)
>          }
>      }
>  
> -    if (s->start_mode == 0 && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
> +    if (s->start_mode == MODE_ADD && s->pad_start > 0 && ff_outlink_frame_wanted(outlink)) {
>          frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
>          if (!frame)
>              return AVERROR(ENOMEM);
> @@ -106,7 +112,7 @@ static int activate(AVFilterContext *ctx)
>          return ff_filter_frame(outlink, frame);
>      }
>  
> -    if (s->start_mode == 1 && s->pad_start > 0) {
> +    if (s->start_mode == MODE_CLONE && s->pad_start > 0) {
>          if (s->eof) {
>              ff_outlink_set_status(outlink, AVERROR_EOF, 0);
>              return 0;
> @@ -133,7 +139,7 @@ static int activate(AVFilterContext *ctx)
>          if (ret < 0)
>              return ret;
>          if (ret > 0) {
> -            if (s->stop_mode == 1 && s->pad_stop != 0) {
> +            if (s->stop_mode == MODE_CLONE && s->pad_stop != 0) {
>                  av_frame_free(&s->cache_stop);
>                  s->cache_stop = av_frame_clone(frame);
>              }
> @@ -147,14 +153,14 @@ static int activate(AVFilterContext *ctx)
>              ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
>              return 0;
>          }
> -        if (s->stop_mode == 0) {
> +        if (s->stop_mode == MODE_ADD) {
>              frame = ff_get_video_buffer(outlink, outlink->w, outlink->h);
>              if (!frame)
>                  return AVERROR(ENOMEM);
>              ff_fill_rectangle(&s->draw, &s->color,
>                                frame->data, frame->linesize,
>                                0, 0, frame->width, frame->height);
> -        } else if (s->stop_mode == 1) {
> +        } else if (s->stop_mode == MODE_CLONE) {
>              if (!s->cache_stop) {
>                  s->pad_stop = 0;
>                  ff_outlink_set_status(outlink, AVERROR_EOF, s->pts);
> -- 
> 2.37.0 (Apple Git-136)
> 
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

Tested, LGTM.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-05-22 16:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-19 10:42 [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
2023-04-19 10:42 ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
2023-04-19 10:45   ` Marvin Scholz
2023-05-01 12:18 ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Marvin Scholz
2023-05-01 12:18   ` [FFmpeg-devel] [PATCH 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
2023-05-05 20:02     ` Thilo Borgmann
2023-05-05 20:01   ` [FFmpeg-devel] [PATCH 1/2] avfilter/vf_tpad: use enum for start/stop_mode Thilo Borgmann
2023-05-22 10:14 ` [FFmpeg-devel] [PATCH v3 " Marvin Scholz
2023-05-22 10:14   ` [FFmpeg-devel] [PATCH v3 2/2] avfilter/vf_tpad: accept hardware frames in clone-only mode Marvin Scholz
2023-05-22 16:37   ` [FFmpeg-devel] [PATCH v3 1/2] avfilter/vf_tpad: use enum for start/stop_mode Niklas Haas

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git