diff mbox series

[FFmpeg-devel,v2] libavcodec/qsvenc_hevc: encode RGB format rawvideo

Message ID 20220215070053.653351-1-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel,v2] libavcodec/qsvenc_hevc: encode RGB format rawvideo | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Wenbin Chen Feb. 15, 2022, 7 a.m. UTC
Add support for hevc_qsv to input RGB format frame. It will
transform frame to yuv inside MediaSDK instead of using auto
scale. Now hevc_qsv supports directly encoding BGRA and X2RGB10
format. X2RGB10 is only supported in VDENC (-low_power 1).
The X2RGB10 correspond to the A2RGB20 format in MediaSDK.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavcodec/qsv.c         | 16 ++++++++++++++++
 libavcodec/qsvenc.c      | 13 +++++++++++++
 libavcodec/qsvenc_hevc.c |  6 ++++++
 3 files changed, 35 insertions(+)

Comments

Xiang, Haihao Feb. 17, 2022, 1:44 a.m. UTC | #1
On Tue, 2022-02-15 at 15:00 +0800, Wenbin Chen wrote:
> Add support for hevc_qsv to input RGB format frame. It will
> transform frame to yuv inside MediaSDK instead of using auto
> scale. Now hevc_qsv supports directly encoding BGRA and X2RGB10
> format. X2RGB10 is only supported in VDENC (-low_power 1).
> The X2RGB10 correspond to the A2RGB20 format in MediaSDK.
> 
> Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> ---
>  libavcodec/qsv.c         | 16 ++++++++++++++++
>  libavcodec/qsvenc.c      | 13 +++++++++++++
>  libavcodec/qsvenc_hevc.c |  6 ++++++
>  3 files changed, 35 insertions(+)
> 
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 1a432dbd82..b75877e698 100644
> --- a/libavcodec/qsv.c
> +++ b/libavcodec/qsv.c
> @@ -189,6 +189,12 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
>      case MFX_FOURCC_NV12: return AV_PIX_FMT_NV12;
>      case MFX_FOURCC_P010: return AV_PIX_FMT_P010;
>      case MFX_FOURCC_P8:   return AV_PIX_FMT_PAL8;
> +#if QSV_VERSION_ATLEAST(1, 9)
> +    case MFX_FOURCC_A2RGB10: return AV_PIX_FMT_X2RGB10;
> +#endif
> +#if QSV_VERSION_ATLEAST(1, 17)
> +    case MFX_FOURCC_RGB4: return AV_PIX_FMT_BGRA;
> +#endif
>  #if CONFIG_VAAPI
>      case MFX_FOURCC_YUY2: return AV_PIX_FMT_YUYV422;
>  #if QSV_VERSION_ATLEAST(1, 27)
> @@ -211,6 +217,16 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t
> *fourcc)
>      case AV_PIX_FMT_P010:
>          *fourcc = MFX_FOURCC_P010;
>          return AV_PIX_FMT_P010;
> +#if QSV_VERSION_ATLEAST(1, 9)
> +    case AV_PIX_FMT_X2RGB10:
> +        *fourcc = MFX_FOURCC_A2RGB10;
> +        return AV_PIX_FMT_X2RGB10;
> +#endif
> +#if QSV_VERSION_ATLEAST(1, 17)
> +    case AV_PIX_FMT_BGRA:
> +        *fourcc = MFX_FOURCC_RGB4;
> +        return AV_PIX_FMT_BGRA;
> +#endif
>  #if CONFIG_VAAPI
>      case AV_PIX_FMT_YUV422P:
>      case AV_PIX_FMT_YUYV422:
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 07be4287b7..104133fc59 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -715,6 +715,11 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>      if (ret < 0)
>          return AVERROR_BUG;
>  
> +    if (sw_format == AV_PIX_FMT_X2RGB10 && q->low_power != 1) {

The SDK may choose a workable mode if low_power is set to auto.

Thanks
Haihao

> +        av_log(avctx, AV_LOG_ERROR, "Only VDENC support encoding x2rgb10\n");
> +        return AVERROR(EINVAL);
> +    }
> +
>      q->param.mfx.FrameInfo.CropX          = 0;
>      q->param.mfx.FrameInfo.CropY          = 0;
>      q->param.mfx.FrameInfo.CropW          = avctx->width;
> @@ -1616,6 +1621,14 @@ static int submit_frame(QSVEncContext *q, const AVFrame
> *frame,
>              qf->surface.Data.V     = qf->surface.Data.UV + 2;
>              break;
>  
> +        case AV_PIX_FMT_X2RGB10:
> +        case AV_PIX_FMT_BGRA:
> +            qf->surface.Data.B         = qf->frame->data[0];
> +            qf->surface.Data.G         = qf->frame->data[0] + 1;
> +            qf->surface.Data.R         = qf->frame->data[0] + 2;
> +            qf->surface.Data.A         = qf->frame->data[0] + 3;
> +            break;
> +
>          default:
>              /* should not reach here */
>              av_assert0(0);
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index 5cac141c4d..ade546d4ca 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -304,6 +304,12 @@ const AVCodec ff_hevc_qsv_encoder = {
>      .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
>                                                      AV_PIX_FMT_P010,
>                                                      AV_PIX_FMT_QSV,
> +#if QSV_VERSION_ATLEAST(1, 17)
> +                                                    AV_PIX_FMT_BGRA,
> +#endif
> +#if QSV_VERSION_ATLEAST(1, 9)
> +                                                    AV_PIX_FMT_X2RGB10,
> +#endif
>                                                      AV_PIX_FMT_NONE },
>      .priv_class     = &class,
>      .defaults       = qsv_enc_defaults,
Wenbin Chen Feb. 18, 2022, 1:45 a.m. UTC | #2
> On Tue, 2022-02-15 at 15:00 +0800, Wenbin Chen wrote:
> > Add support for hevc_qsv to input RGB format frame. It will
> > transform frame to yuv inside MediaSDK instead of using auto
> > scale. Now hevc_qsv supports directly encoding BGRA and X2RGB10
> > format. X2RGB10 is only supported in VDENC (-low_power 1).
> > The X2RGB10 correspond to the A2RGB20 format in MediaSDK.
> >
> > Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
> > ---
> >  libavcodec/qsv.c         | 16 ++++++++++++++++
> >  libavcodec/qsvenc.c      | 13 +++++++++++++
> >  libavcodec/qsvenc_hevc.c |  6 ++++++
> >  3 files changed, 35 insertions(+)
> >
> > diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> > index 1a432dbd82..b75877e698 100644
> > --- a/libavcodec/qsv.c
> > +++ b/libavcodec/qsv.c
> > @@ -189,6 +189,12 @@ enum AVPixelFormat ff_qsv_map_fourcc(uint32_t
> fourcc)
> >      case MFX_FOURCC_NV12: return AV_PIX_FMT_NV12;
> >      case MFX_FOURCC_P010: return AV_PIX_FMT_P010;
> >      case MFX_FOURCC_P8:   return AV_PIX_FMT_PAL8;
> > +#if QSV_VERSION_ATLEAST(1, 9)
> > +    case MFX_FOURCC_A2RGB10: return AV_PIX_FMT_X2RGB10;
> > +#endif
> > +#if QSV_VERSION_ATLEAST(1, 17)
> > +    case MFX_FOURCC_RGB4: return AV_PIX_FMT_BGRA;
> > +#endif
> >  #if CONFIG_VAAPI
> >      case MFX_FOURCC_YUY2: return AV_PIX_FMT_YUYV422;
> >  #if QSV_VERSION_ATLEAST(1, 27)
> > @@ -211,6 +217,16 @@ int ff_qsv_map_pixfmt(enum AVPixelFormat
> format, uint32_t
> > *fourcc)
> >      case AV_PIX_FMT_P010:
> >          *fourcc = MFX_FOURCC_P010;
> >          return AV_PIX_FMT_P010;
> > +#if QSV_VERSION_ATLEAST(1, 9)
> > +    case AV_PIX_FMT_X2RGB10:
> > +        *fourcc = MFX_FOURCC_A2RGB10;
> > +        return AV_PIX_FMT_X2RGB10;
> > +#endif
> > +#if QSV_VERSION_ATLEAST(1, 17)
> > +    case AV_PIX_FMT_BGRA:
> > +        *fourcc = MFX_FOURCC_RGB4;
> > +        return AV_PIX_FMT_BGRA;
> > +#endif
> >  #if CONFIG_VAAPI
> >      case AV_PIX_FMT_YUV422P:
> >      case AV_PIX_FMT_YUYV422:
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index 07be4287b7..104133fc59 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -715,6 +715,11 @@ static int init_video_param(AVCodecContext
> *avctx,
> > QSVEncContext *q)
> >      if (ret < 0)
> >          return AVERROR_BUG;
> >
> > +    if (sw_format == AV_PIX_FMT_X2RGB10 && q->low_power != 1) {
> 
> The SDK may choose a workable mode if low_power is set to auto.
> 
> Thanks
> Haihao

Thanks for your information. I will update patch.

> 
> > +        av_log(avctx, AV_LOG_ERROR, "Only VDENC support encoding
> x2rgb10\n");
> > +        return AVERROR(EINVAL);
> > +    }
> > +
> >      q->param.mfx.FrameInfo.CropX          = 0;
> >      q->param.mfx.FrameInfo.CropY          = 0;
> >      q->param.mfx.FrameInfo.CropW          = avctx->width;
> > @@ -1616,6 +1621,14 @@ static int submit_frame(QSVEncContext *q,
> const AVFrame
> > *frame,
> >              qf->surface.Data.V     = qf->surface.Data.UV + 2;
> >              break;
> >
> > +        case AV_PIX_FMT_X2RGB10:
> > +        case AV_PIX_FMT_BGRA:
> > +            qf->surface.Data.B         = qf->frame->data[0];
> > +            qf->surface.Data.G         = qf->frame->data[0] + 1;
> > +            qf->surface.Data.R         = qf->frame->data[0] + 2;
> > +            qf->surface.Data.A         = qf->frame->data[0] + 3;
> > +            break;
> > +
> >          default:
> >              /* should not reach here */
> >              av_assert0(0);
> > diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> > index 5cac141c4d..ade546d4ca 100644
> > --- a/libavcodec/qsvenc_hevc.c
> > +++ b/libavcodec/qsvenc_hevc.c
> > @@ -304,6 +304,12 @@ const AVCodec ff_hevc_qsv_encoder = {
> >      .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
> >                                                      AV_PIX_FMT_P010,
> >                                                      AV_PIX_FMT_QSV,
> > +#if QSV_VERSION_ATLEAST(1, 17)
> > +                                                    AV_PIX_FMT_BGRA,
> > +#endif
> > +#if QSV_VERSION_ATLEAST(1, 9)
> > +                                                    AV_PIX_FMT_X2RGB10,
> > +#endif
> >                                                      AV_PIX_FMT_NONE },
> >      .priv_class     = &class,
> >      .defaults       = qsv_enc_defaults,
> _______________________________________________
> 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".
diff mbox series

Patch

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index 1a432dbd82..b75877e698 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -189,6 +189,12 @@  enum AVPixelFormat ff_qsv_map_fourcc(uint32_t fourcc)
     case MFX_FOURCC_NV12: return AV_PIX_FMT_NV12;
     case MFX_FOURCC_P010: return AV_PIX_FMT_P010;
     case MFX_FOURCC_P8:   return AV_PIX_FMT_PAL8;
+#if QSV_VERSION_ATLEAST(1, 9)
+    case MFX_FOURCC_A2RGB10: return AV_PIX_FMT_X2RGB10;
+#endif
+#if QSV_VERSION_ATLEAST(1, 17)
+    case MFX_FOURCC_RGB4: return AV_PIX_FMT_BGRA;
+#endif
 #if CONFIG_VAAPI
     case MFX_FOURCC_YUY2: return AV_PIX_FMT_YUYV422;
 #if QSV_VERSION_ATLEAST(1, 27)
@@ -211,6 +217,16 @@  int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc)
     case AV_PIX_FMT_P010:
         *fourcc = MFX_FOURCC_P010;
         return AV_PIX_FMT_P010;
+#if QSV_VERSION_ATLEAST(1, 9)
+    case AV_PIX_FMT_X2RGB10:
+        *fourcc = MFX_FOURCC_A2RGB10;
+        return AV_PIX_FMT_X2RGB10;
+#endif
+#if QSV_VERSION_ATLEAST(1, 17)
+    case AV_PIX_FMT_BGRA:
+        *fourcc = MFX_FOURCC_RGB4;
+        return AV_PIX_FMT_BGRA;
+#endif
 #if CONFIG_VAAPI
     case AV_PIX_FMT_YUV422P:
     case AV_PIX_FMT_YUYV422:
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 07be4287b7..104133fc59 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -715,6 +715,11 @@  static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
     if (ret < 0)
         return AVERROR_BUG;
 
+    if (sw_format == AV_PIX_FMT_X2RGB10 && q->low_power != 1) {
+        av_log(avctx, AV_LOG_ERROR, "Only VDENC support encoding x2rgb10\n");
+        return AVERROR(EINVAL);
+    }
+
     q->param.mfx.FrameInfo.CropX          = 0;
     q->param.mfx.FrameInfo.CropY          = 0;
     q->param.mfx.FrameInfo.CropW          = avctx->width;
@@ -1616,6 +1621,14 @@  static int submit_frame(QSVEncContext *q, const AVFrame *frame,
             qf->surface.Data.V     = qf->surface.Data.UV + 2;
             break;
 
+        case AV_PIX_FMT_X2RGB10:
+        case AV_PIX_FMT_BGRA:
+            qf->surface.Data.B         = qf->frame->data[0];
+            qf->surface.Data.G         = qf->frame->data[0] + 1;
+            qf->surface.Data.R         = qf->frame->data[0] + 2;
+            qf->surface.Data.A         = qf->frame->data[0] + 3;
+            break;
+
         default:
             /* should not reach here */
             av_assert0(0);
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 5cac141c4d..ade546d4ca 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -304,6 +304,12 @@  const AVCodec ff_hevc_qsv_encoder = {
     .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
                                                     AV_PIX_FMT_P010,
                                                     AV_PIX_FMT_QSV,
+#if QSV_VERSION_ATLEAST(1, 17)
+                                                    AV_PIX_FMT_BGRA,
+#endif
+#if QSV_VERSION_ATLEAST(1, 9)
+                                                    AV_PIX_FMT_X2RGB10,
+#endif
                                                     AV_PIX_FMT_NONE },
     .priv_class     = &class,
     .defaults       = qsv_enc_defaults,