diff mbox series

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

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

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 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

Chen, Wenbin Feb. 14, 2022, 6:50 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.

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

Comments

Andreas Rheinhardt Feb. 14, 2022, 9:02 a.m. UTC | #1
Wenbin Chen:
> 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.
> 
> Sigend-off-by: Wenbin Chen <wenbin.chen@intel.com>
     ^
Are you writing this manually?

- Andreas
Chen, Wenbin Feb. 15, 2022, 6:24 a.m. UTC | #2
> Wenbin Chen:
> > 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.
> >
> > Sigend-off-by: Wenbin Chen <wenbin.chen@intel.com>
>      ^
> Are you writing this manually?

I always thought it is manually writing. I just searched and found that
there is  a "-s" option. Will fix this.
Thanks for your reminder.

> 
> - Andreas
> _______________________________________________
> 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..f834691d1a 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -776,6 +776,13 @@  static int init_video_param(AVCodecContext *avctx, QSVEncContext *q)
     brc_param_multiplier       = (FFMAX(FFMAX3(target_bitrate_kbps, max_bitrate_kbps, buffer_size_in_kilobytes),
                                   initial_delay_in_kilobytes) + 0x10000) / 0x10000;
 
+#if QSV_VERSION_ATLEAST(1, 9)
+    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);
+    }
+#endif
+
     switch (q->param.mfx.RateControlMethod) {
     case MFX_RATECONTROL_CBR:
     case MFX_RATECONTROL_VBR:
@@ -1616,6 +1623,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,