diff mbox series

[FFmpeg-devel,3/3] scale_qsv frame crop support

Message ID 20240910181057.43453-3-koushd@gmail.com
State New
Headers show
Series [FFmpeg-devel,1/3] scale_vt frame crop support | expand

Checks

Context Check Description
andriy/commit_msg_x86 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
yinshiyou/commit_msg_loongarch64 warning The first line of the commit message must start with a context terminated by a colon and a space, for example "lavu/opt: " or "doc: ".
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Koushik Dutta Sept. 10, 2024, 6:10 p.m. UTC
The crop filter has no effect on scale_qsv:

-vf crop=100:100,scale_qsv=300x300

Hardware frames (AV_PIX_FMT_FLAG_HWACCEL) are expected to use the crop_* properties,
as seen in the implementation vf_crop.c.

This patch is slightly different from the previously submitted patches
since qsv supports frame crop via the vpp_qsv filter. If no explicit crop
is detected via that filter, AVFrame.crop_* will be used instead.
Removal of vpp_qsv's crop argument may be warranted.
---
 libavfilter/qsvvpp.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Wang, Fei W Sept. 12, 2024, 7:16 a.m. UTC | #1
On Tue, 2024-09-10 at 11:10 -0700, Koushik Dutta wrote:
> The crop filter has no effect on scale_qsv:
> 
> -vf crop=100:100,scale_qsv=300x300
> 

How about to use vpp_qsv filter directly? It support both scale and
crop via its options which is much more easy to use.

Thanks
Fei

> Hardware frames (AV_PIX_FMT_FLAG_HWACCEL) are expected to use the
> crop_* properties,
> as seen in the implementation vf_crop.c.
> 
> This patch is slightly different from the previously submitted
> patches
> since qsv supports frame crop via the vpp_qsv filter. If no explicit
> crop
> is detected via that filter, AVFrame.crop_* will be used instead.
> Removal of vpp_qsv's crop argument may be warranted.
> ---
>  libavfilter/qsvvpp.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
> index 0818ada117..05ce387bc3 100644
> --- a/libavfilter/qsvvpp.c
> +++ b/libavfilter/qsvvpp.c
> @@ -467,6 +467,16 @@ static QSVFrame *submit_frame(QSVVPPContext *s,
> AVFilterLink *inlink, AVFrame *p
>      else if (qsv_frame->frame->repeat_pict == 4)
>          qsv_frame->surface.Info.PicStruct |=
> MFX_PICSTRUCT_FRAME_TRIPLING;
>  
> +    // if crop arguments are not present from the vpp_qsv filter,
> use the provided AVFrame
> +    // crop_* members instead.
> +    if (!qsv_frame->surface.Info.CropX && !qsv_frame-
> >surface.Info.CropY
> +        && qsv_frame->surface.Info.CropW == picref->width &&
> qsv_frame->surface.Info.CropH == picref->height) {
> +        qsv_frame->surface.Info.CropW = (mfxU16)((picref->width -
> picref->crop_right) - picref->crop_left);
> +        qsv_frame->surface.Info.CropH = (mfxU16)((picref->height -
> picref->crop_bottom) - picref->crop_top);
> +        qsv_frame->surface.Info.CropX = (mfxU16)picref->crop_left;
> +        qsv_frame->surface.Info.CropY = (mfxU16)picref->crop_top;
> +    }
> +
>      return qsv_frame;
>  }
>
diff mbox series

Patch

diff --git a/libavfilter/qsvvpp.c b/libavfilter/qsvvpp.c
index 0818ada117..05ce387bc3 100644
--- a/libavfilter/qsvvpp.c
+++ b/libavfilter/qsvvpp.c
@@ -467,6 +467,16 @@  static QSVFrame *submit_frame(QSVVPPContext *s, AVFilterLink *inlink, AVFrame *p
     else if (qsv_frame->frame->repeat_pict == 4)
         qsv_frame->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
 
+    // if crop arguments are not present from the vpp_qsv filter, use the provided AVFrame
+    // crop_* members instead.
+    if (!qsv_frame->surface.Info.CropX && !qsv_frame->surface.Info.CropY
+        && qsv_frame->surface.Info.CropW == picref->width && qsv_frame->surface.Info.CropH == picref->height) {
+        qsv_frame->surface.Info.CropW = (mfxU16)((picref->width - picref->crop_right) - picref->crop_left);
+        qsv_frame->surface.Info.CropH = (mfxU16)((picref->height - picref->crop_bottom) - picref->crop_top);
+        qsv_frame->surface.Info.CropX = (mfxU16)picref->crop_left;
+        qsv_frame->surface.Info.CropY = (mfxU16)picref->crop_top;
+    }
+
     return qsv_frame;
 }