diff mbox series

[FFmpeg-devel] libavutil/hwcontext_qsv: Align width and heigh when download qsv frame

Message ID 20220331074341.896911-1-wenbin.chen@intel.com
State New
Headers show
Series [FFmpeg-devel] libavutil/hwcontext_qsv: Align width and heigh when download qsv frame | expand

Checks

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

Commit Message

Chen, Wenbin March 31, 2022, 7:43 a.m. UTC
The width and height for qsv frame to download need to be
aligned with 16. Add the alignment operation.
Now the following command works:
ffmpeg -hwaccel qsv -f rawvideo -s 1920x1080 -pix_fmt yuv420p -i \
input.yuv -vf "hwupload=extra_hw_frames=16,format=qsv,hwdownload, \
format=nv12" -f null -

Signed-off-by: Wenbin Chen <wenbin.chen@intel.com>
---
 libavutil/hwcontext_qsv.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 95f8071abe..1e7c065902 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -1063,6 +1063,40 @@  static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
     if (ret < 0)
         return ret;
 
+    /* According to MSDK spec for mfxframeinfo, "Width must be a multiple of 16.
+     * Height must be a multiple of 16 for progressive frame sequence and a
+     * multiple of 32 otherwise.", so allign all frames to 16 before downloading. */
+    if (ctx->height & 15 || dst->linesize[0] & 15) {
+        AVFrame *tmp_frame;
+        tmp_frame = av_frame_alloc();
+        if (!tmp_frame)
+            return AVERROR(ENOMEM);
+        ret = av_frame_ref(tmp_frame, dst);
+        if (ret < 0) {
+            av_frame_free(&tmp_frame);
+            return ret;
+        }
+        av_frame_unref(dst);
+
+        dst->width  = FFALIGN(tmp_frame->width, 16);
+        dst->height = FFALIGN(ctx->height, 16);
+        dst->format = tmp_frame->format;
+        ret = av_frame_get_buffer(dst, 0);
+        if (ret < 0) {
+            av_frame_free(&tmp_frame);
+            return ret;
+        }
+
+        dst->width = tmp_frame->width;
+        dst->height = tmp_frame->height;
+        ret = av_frame_copy_props(dst, tmp_frame);
+        if (ret < 0) {
+            av_frame_free(&tmp_frame);
+            return ret;
+        }
+        av_frame_free(&tmp_frame);
+    }
+
     if (!s->session_download) {
         if (s->child_frames_ref)
             return qsv_transfer_data_child(ctx, dst, src);