diff mbox series

[FFmpeg-devel,v3,2/2] libavcodec/qsvenc: Add more pixel format support to qsvenc

Message ID 20220406084804.1043196-2-wenbin.chen@intel.com
State Accepted
Commit fb8880906375a2a17ed94c2ef7b9048fd25a75ec
Headers show
Series [FFmpeg-devel,v3,1/2] libavcodec/qsvdec: Add more pixel format support to qsvdec | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_aarch64_jetson fail Make failed
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

Chen, Wenbin April 6, 2022, 8:48 a.m. UTC
Qsv encoder only support input P010 and nv12 format directly from system
memory. For other format, we need to upload frame to device memory and
input qsv format to encoder. Now add other system memory format support
to qsv encoder.

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavcodec/qsvenc.c      | 30 ++++--------------------------
 libavcodec/qsvenc_hevc.c |  2 ++
 2 files changed, 6 insertions(+), 26 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 55ce3d2499..345df0190c 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1606,32 +1606,10 @@  static int submit_frame(QSVEncContext *q, const AVFrame *frame,
         else if (frame->repeat_pict == 4)
             qf->surface.Info.PicStruct |= MFX_PICSTRUCT_FRAME_TRIPLING;
 
-        qf->surface.Data.PitchLow  = qf->frame->linesize[0];
-        qf->surface.Data.Y         = qf->frame->data[0];
-        qf->surface.Data.UV        = qf->frame->data[1];
-
-        /* The SDK checks Data.V when using system memory for VP9 encoding */
-        switch (frame->format) {
-        case AV_PIX_FMT_NV12:
-            qf->surface.Data.V     = qf->surface.Data.UV + 1;
-            break;
-
-        case AV_PIX_FMT_P010:
-            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);
-            break;
+        ret = ff_qsv_map_frame_to_surface(qf->frame, &qf->surface);
+        if (ret < 0) {
+            av_log(q->avctx, AV_LOG_ERROR, "map frame to surface failed.\n");
+            return ret;
         }
     }
     qf->surface.Data.TimeStamp = av_rescale_q(frame->pts, q->avctx->time_base, (AVRational){1, 90000});
diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
index 36c2d484ad..3a2d50e332 100644
--- a/libavcodec/qsvenc_hevc.c
+++ b/libavcodec/qsvenc_hevc.c
@@ -303,6 +303,8 @@  const FFCodec ff_hevc_qsv_encoder = {
     .p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HYBRID,
     .p.pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_NV12,
                                                     AV_PIX_FMT_P010,
+                                                    AV_PIX_FMT_YUYV422,
+                                                    AV_PIX_FMT_Y210,
                                                     AV_PIX_FMT_QSV,
 #if QSV_VERSION_ATLEAST(1, 17)
                                                     AV_PIX_FMT_BGRA,