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] lavfi/qsv: Copy metadata fields from the given input
@ 2024-04-25  5:18 Xiang, Haihao
  2024-04-28  3:14 ` Xiang, Haihao
  0 siblings, 1 reply; 2+ messages in thread
From: Xiang, Haihao @ 2024-04-25  5:18 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Haihao Xiang

From: Haihao Xiang <haihao.xiang@intel.com>

Currently it always copies the metadata fields from the last input when
there are multiple inputs for the filter. For example, the metadata
fields from input1 are copied to the output for overlay_qsv filter,
however for regular overlay filters, the metadata fields from input0 are
copied to the output. With this fix, we may copy the metadata fields
from input0 to the ouput as well.

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
 libavfilter/qsvvpp.c         | 29 +++++++++++------------------
 libavfilter/qsvvpp.h         |  2 +-
 libavfilter/vf_overlay_qsv.c |  9 ++++++---
 libavfilter/vf_stack_qsv.c   |  9 ++++++---
 libavfilter/vf_vpp_qsv.c     |  2 +-
 5 files changed, 25 insertions(+), 26 deletions(-)

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 8c92fec0c1..10d970652e 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -441,11 +441,6 @@ static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p
                 av_frame_free(&qsv_frame->frame);
                 return NULL;
             }
-
-            if (av_frame_copy_props(qsv_frame->frame, picref) < 0) {
-                av_frame_free(&qsv_frame->frame);
-                return NULL;
-            }
         } else
             qsv_frame->frame = av_frame_clone(picref);
 
@@ -494,12 +489,6 @@ static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink, const AVFr
         if (!out_frame->frame)
             return NULL;
 
-        ret = av_frame_copy_props(out_frame->frame, in);
-        if (ret < 0) {
-            av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from src to dst.\n");
-            return NULL;
-        }
-
         ret = av_hwframe_get_buffer(outlink->hw_frames_ctx, out_frame->frame, 0);
         if (ret < 0) {
             av_log(ctx, AV_LOG_ERROR, "Can't allocate a surface.\n");
@@ -516,12 +505,6 @@ static QSVFrame *query_frame(QSVVPPContext *s, AVFilterLink *outlink, const AVFr
         if (!out_frame->frame)
             return NULL;
 
-        ret = av_frame_copy_props(out_frame->frame, in);
-        if (ret < 0) {
-            av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from src to dst.\n");
-            return NULL;
-        }
-
         ret = map_frame_to_surface(out_frame->frame,
                                    &out_frame->surface);
         if (ret < 0)
@@ -958,7 +941,7 @@ int ff_qsvvpp_close(AVFilterContext *avctx)
     return 0;
 }
 
-int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref)
+int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picref, AVFrame *propref)
 {
     AVFilterContext  *ctx     = inlink->dst;
     AVFilterLink     *outlink = ctx->outputs[0];
@@ -1015,6 +998,16 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *picr
                 return AVERROR(EAGAIN);
             break;
         }
+
+        if (propref) {
+            ret1 = av_frame_copy_props(out_frame->frame, propref);
+            if (ret1 < 0) {
+                av_frame_free(&out_frame->frame);
+                av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from src to dst.\n");
+                return ret1;
+            }
+        }
+
         out_frame->frame->pts = av_rescale_q(out_frame->surface.Data.TimeStamp,
                                              default_tb, outlink->time_base);
 
diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
index 4eea7a46c7..3b9192b62e 100644
--- a/libavfilter/qsvvpp.h
+++ b/libavfilter/qsvvpp.h
@@ -131,7 +131,7 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam *param);
 int ff_qsvvpp_close(AVFilterContext *avctx);
 
 /* vpp filter frame and call the cb if needed */
-int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame *frame);
+int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame *frame, AVFrame *propref);
 
 int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern,
                               const char *extra_string);
diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
index 0f52c93245..059602fe03 100644
--- a/libavfilter/vf_overlay_qsv.c
+++ b/libavfilter/vf_overlay_qsv.c
@@ -228,13 +228,16 @@ static int process_frame(FFFrameSync *fs)
 {
     AVFilterContext  *ctx = fs->parent;
     QSVVPPContext    *qsv = fs->opaque;
-    AVFrame        *frame = NULL;
+    AVFrame        *frame = NULL, *propref = NULL;
     int               ret = 0, i;
 
     for (i = 0; i < ctx->nb_inputs; i++) {
         ret = ff_framesync_get_frame(fs, i, &frame, 0);
-        if (ret == 0)
-            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame);
+        if (ret == 0) {
+            if (i == 0)
+                propref = frame;
+            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame, propref);
+        }
         if (ret < 0 && ret != AVERROR(EAGAIN))
             break;
     }
diff --git a/libavfilter/vf_stack_qsv.c b/libavfilter/vf_stack_qsv.c
index abaf156915..d4c1ac997f 100644
--- a/libavfilter/vf_stack_qsv.c
+++ b/libavfilter/vf_stack_qsv.c
@@ -71,13 +71,16 @@ static int process_frame(FFFrameSync *fs)
 {
     AVFilterContext *ctx = fs->parent;
     QSVVPPContext *qsv = fs->opaque;
-    AVFrame *frame = NULL;
+    AVFrame *frame = NULL, *propref = NULL;
     int ret = 0;
 
     for (int i = 0; i < ctx->nb_inputs; i++) {
         ret = ff_framesync_get_frame(fs, i, &frame, 0);
-        if (ret == 0)
-            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame);
+        if (ret == 0) {
+            if (i == 0)
+                propref = frame;
+            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame, propref);
+        }
         if (ret < 0 && ret != AVERROR(EAGAIN))
             break;
     }
diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
index 598c85be09..6071c46ca1 100644
--- a/libavfilter/vf_vpp_qsv.c
+++ b/libavfilter/vf_vpp_qsv.c
@@ -748,7 +748,7 @@ static int activate(AVFilterContext *ctx)
 
     if (qsv->session) {
         if (in || qsv->eof) {
-            ret = ff_qsvvpp_filter_frame(qsv, inlink, in);
+            ret = ff_qsvvpp_filter_frame(qsv, inlink, in, in);
             av_frame_free(&in);
             if (ret == AVERROR(EAGAIN))
                 goto not_ready;
-- 
2.34.1

_______________________________________________
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] 2+ messages in thread

* Re: [FFmpeg-devel] [PATCH] lavfi/qsv: Copy metadata fields from the given input
  2024-04-25  5:18 [FFmpeg-devel] [PATCH] lavfi/qsv: Copy metadata fields from the given input Xiang, Haihao
@ 2024-04-28  3:14 ` Xiang, Haihao
  0 siblings, 0 replies; 2+ messages in thread
From: Xiang, Haihao @ 2024-04-28  3:14 UTC (permalink / raw)
  To: ffmpeg-devel

On Do, 2024-04-25 at 13:18 +0800, Xiang, Haihao wrote:
> From: Haihao Xiang <haihao.xiang@intel.com>
> 
> Currently it always copies the metadata fields from the last input when
> there are multiple inputs for the filter. For example, the metadata
> fields from input1 are copied to the output for overlay_qsv filter,
> however for regular overlay filters, the metadata fields from input0 are
> copied to the output. With this fix, we may copy the metadata fields
> from input0 to the ouput as well.
> 
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
>  libavfilter/qsvvpp.c         | 29 +++++++++++------------------
>  libavfilter/qsvvpp.h         |  2 +-
>  libavfilter/vf_overlay_qsv.c |  9 ++++++---
>  libavfilter/vf_stack_qsv.c   |  9 ++++++---
>  libavfilter/vf_vpp_qsv.c     |  2 +-
>  5 files changed, 25 insertions(+), 26 deletions(-)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 8c92fec0c1..10d970652e 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -441,11 +441,6 @@ static QSVFrame *submit_frame(QSVVPPContext *s,
> AVFilterLink *inlink, AVFrame *p
>                  av_frame_free(&qsv_frame->frame);
>                  return NULL;
>              }
> -
> -            if (av_frame_copy_props(qsv_frame->frame, picref) < 0) {
> -                av_frame_free(&qsv_frame->frame);
> -                return NULL;
> -            }
>          } else
>              qsv_frame->frame = av_frame_clone(picref);
>  
> @@ -494,12 +489,6 @@ static QSVFrame *query_frame(QSVVPPContext *s,
> AVFilterLink *outlink, const AVFr
>          if (!out_frame->frame)
>              return NULL;
>  
> -        ret = av_frame_copy_props(out_frame->frame, in);
> -        if (ret < 0) {
> -            av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from
> src to dst.\n");
> -            return NULL;
> -        }
> -
>          ret = av_hwframe_get_buffer(outlink->hw_frames_ctx, out_frame->frame,
> 0);
>          if (ret < 0) {
>              av_log(ctx, AV_LOG_ERROR, "Can't allocate a surface.\n");
> @@ -516,12 +505,6 @@ static QSVFrame *query_frame(QSVVPPContext *s,
> AVFilterLink *outlink, const AVFr
>          if (!out_frame->frame)
>              return NULL;
>  
> -        ret = av_frame_copy_props(out_frame->frame, in);
> -        if (ret < 0) {
> -            av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields from
> src to dst.\n");
> -            return NULL;
> -        }
> -
>          ret = map_frame_to_surface(out_frame->frame,
>                                     &out_frame->surface);
>          if (ret < 0)
> @@ -958,7 +941,7 @@ int ff_qsvvpp_close(AVFilterContext *avctx)
>      return 0;
>  }
>  
> -int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame
> *picref)
> +int ff_qsvvpp_filter_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame
> *picref, AVFrame *propref)
>  {
>      AVFilterContext  *ctx     = inlink->dst;
>      AVFilterLink     *outlink = ctx->outputs[0];
> @@ -1015,6 +998,16 @@ int ff_qsvvpp_filter_frame(QSVVPPContext *s,
> AVFilterLink *inlink, AVFrame *picr
>                  return AVERROR(EAGAIN);
>              break;
>          }
> +
> +        if (propref) {
> +            ret1 = av_frame_copy_props(out_frame->frame, propref);
> +            if (ret1 < 0) {
> +                av_frame_free(&out_frame->frame);
> +                av_log(ctx, AV_LOG_ERROR, "Failed to copy metadata fields
> from src to dst.\n");
> +                return ret1;
> +            }
> +        }
> +
>          out_frame->frame->pts = av_rescale_q(out_frame-
> >surface.Data.TimeStamp,
>                                               default_tb, outlink->time_base);
>  
> diff --git a/libavfilter/qsvvpp.h b/libavfilter/qsvvpp.h
> index 4eea7a46c7..3b9192b62e 100644
> --- a/libavfilter/qsvvpp.h
> +++ b/libavfilter/qsvvpp.h
> @@ -131,7 +131,7 @@ int ff_qsvvpp_init(AVFilterContext *avctx, QSVVPPParam
> *param);
>  int ff_qsvvpp_close(AVFilterContext *avctx);
>  
>  /* vpp filter frame and call the cb if needed */
> -int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame
> *frame);
> +int ff_qsvvpp_filter_frame(QSVVPPContext *vpp, AVFilterLink *inlink, AVFrame
> *frame, AVFrame *propref);
>  
>  int ff_qsvvpp_print_iopattern(void *log_ctx, int mfx_iopattern,
>                                const char *extra_string);
> diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> index 0f52c93245..059602fe03 100644
> --- a/libavfilter/vf_overlay_qsv.c
> +++ b/libavfilter/vf_overlay_qsv.c
> @@ -228,13 +228,16 @@ static int process_frame(FFFrameSync *fs)
>  {
>      AVFilterContext  *ctx = fs->parent;
>      QSVVPPContext    *qsv = fs->opaque;
> -    AVFrame        *frame = NULL;
> +    AVFrame        *frame = NULL, *propref = NULL;
>      int               ret = 0, i;
>  
>      for (i = 0; i < ctx->nb_inputs; i++) {
>          ret = ff_framesync_get_frame(fs, i, &frame, 0);
> -        if (ret == 0)
> -            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame);
> +        if (ret == 0) {
> +            if (i == 0)
> +                propref = frame;
> +            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame,
> propref);
> +        }
>          if (ret < 0 && ret != AVERROR(EAGAIN))
>              break;
>      }
> diff --git a/libavfilter/vf_stack_qsv.c b/libavfilter/vf_stack_qsv.c
> index abaf156915..d4c1ac997f 100644
> --- a/libavfilter/vf_stack_qsv.c
> +++ b/libavfilter/vf_stack_qsv.c
> @@ -71,13 +71,16 @@ static int process_frame(FFFrameSync *fs)
>  {
>      AVFilterContext *ctx = fs->parent;
>      QSVVPPContext *qsv = fs->opaque;
> -    AVFrame *frame = NULL;
> +    AVFrame *frame = NULL, *propref = NULL;
>      int ret = 0;
>  
>      for (int i = 0; i < ctx->nb_inputs; i++) {
>          ret = ff_framesync_get_frame(fs, i, &frame, 0);
> -        if (ret == 0)
> -            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame);
> +        if (ret == 0) {
> +            if (i == 0)
> +                propref = frame;
> +            ret = ff_qsvvpp_filter_frame(qsv, ctx->inputs[i], frame,
> propref);
> +        }
>          if (ret < 0 && ret != AVERROR(EAGAIN))
>              break;
>      }
> diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
> index 598c85be09..6071c46ca1 100644
> --- a/libavfilter/vf_vpp_qsv.c
> +++ b/libavfilter/vf_vpp_qsv.c
> @@ -748,7 +748,7 @@ static int activate(AVFilterContext *ctx)
>  
>      if (qsv->session) {
>          if (in || qsv->eof) {
> -            ret = ff_qsvvpp_filter_frame(qsv, inlink, in);
> +            ret = ff_qsvvpp_filter_frame(qsv, inlink, in, in);
>              av_frame_free(&in);
>              if (ret == AVERROR(EAGAIN))
>                  goto not_ready;

Will apply

-Haihao


_______________________________________________
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] 2+ messages in thread

end of thread, other threads:[~2024-04-28  3:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25  5:18 [FFmpeg-devel] [PATCH] lavfi/qsv: Copy metadata fields from the given input Xiang, Haihao
2024-04-28  3:14 ` Xiang, Haihao

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