[FFmpeg-devel] [PATCH] libavutil/hwcontext_qsv: Command line using hwaccel 'QSV' doesn't work

Huang, Zhengxu zhengxu.maxwell at gmail.com
Mon Jan 9 07:58:39 EET 2017


在 2017/1/8 7:36, Mark Thompson 写道:
> On 06/01/17 06:37, Huang, Zhengxu wrote:
>> Hi
>>
>> According to the suggestion update the patch.
>>
>> thanks.
>>
>>
>>  From 4beadd3c84c797a56c4f375458d0a1e9d9b233c8 Mon Sep 17 00:00:00 2001
>> From: Zhengxu <zhengxu.maxwell at gmail.com>
>> Date: Thu, 5 Jan 2017 14:48:06 +0800
>> Subject: [PATCH] ffmpeg_qsv: Add an option "qsv_child_device" to choose an
>>   proper node for QSV child device(vaapi or dxva2).
>>
>> Reason: For some cases, such as 2 or more graphics card existing, the
>> default command line may fail because ffmpeg open a wrong device node:
>>      ffmpeg -hwaccel qsv -c:v h264_qsv -i test.264 -c:v h264_qsv out.264
>> Let user to choose the proper one by running like below:
>>      ffmpeg -hwaccel qsv -qsv_child_device /dev/dri/renderD128 -c:v h264_qsv \
>> -i test.264 -c:v h264_qsv out.264
> I think it should just be "qsv_device".  It is the device being used by qsv, the fact that it is a child device of another kind (dxva or vaapi) wrapped inside the hwcontext infrastructure isn't really relevant to the ffmpeg utility.
>
>> Signed-off-by: ChaoX A Liu <chaox.a.liu at gmail.com>
>> Signed-off-by: Huang, Zhengxu <zhengxu.maxwell at gmail.com>
>> Signed-off-by: Andrew, Zhang <huazh407 at gmail.com>
>> ---
>>   ffmpeg.h     |  3 +++
>>   ffmpeg_opt.c |  5 +++++
>>   ffmpeg_qsv.c | 11 ++++++++++-
>>   3 files changed, 18 insertions(+), 1 deletion(-)
>>
>> diff --git a/ffmpeg.h b/ffmpeg.h
>> index ebe5bf0..91a3333 100644
>> --- a/ffmpeg.h
>> +++ b/ffmpeg.h
>> @@ -602,6 +602,9 @@ extern const OptionDef options[];
>>   extern const HWAccel hwaccels[];
>>   extern int hwaccel_lax_profile_check;
>>   extern AVBufferRef *hw_device_ctx;
>> +#if CONFIG_QSV
>> +extern char *qsv_child_device;
>> +#endif
>>   
>>   
>>   void term_init(void);
>> diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
>> index 6862456..7fd08a2 100644
>> --- a/ffmpeg_opt.c
>> +++ b/ffmpeg_opt.c
>> @@ -3679,5 +3679,10 @@ const OptionDef options[] = {
>>           "set VAAPI hardware device (DRM path or X11 display name)", "device" },
>>   #endif
>>   
>> +#if CONFIG_QSV
>> +    { "qsv_child_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_child_device },
>> +        "set QSV child device (DRM path or DXVA)", "device"},
> An X11 display will still work here.  Also, maybe clarify that the DXVA case is a DirectX adapter index?
>
> "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", say.
>
>> +#endif
>> +
>>       { NULL, },
>>   };
>> diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c
>> index 68ff5bd..5a6db20 100644
>> --- a/ffmpeg_qsv.c
>> +++ b/ffmpeg_qsv.c
>> @@ -28,6 +28,8 @@
>>   
>>   #include "ffmpeg.h"
>>   
>> +char *qsv_child_device = NULL;
>> +
>>   static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
>>   {
>>       InputStream *ist = s->opaque;
>> @@ -44,9 +46,16 @@ static void qsv_uninit(AVCodecContext *s)
>>   static int qsv_device_init(InputStream *ist)
>>   {
>>       int err;
>> +    AVDictionary *dict = NULL;
>> +
>> +    if (qsv_child_device) {
>> +        err = av_dict_set(&dict, "child_device", qsv_child_device, 0);
>> +        if (err < 0)
>> +            return err;
>> +    }
>>   
>>       err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV,
>> -                                 ist->hwaccel_device, NULL, 0);
>> +                                 ist->hwaccel_device, dict, 0);
>>       if (err < 0) {
>>           av_log(NULL, AV_LOG_ERROR, "Error creating a QSV device\n");
>>           return err;
>> -- 
>> 1.8.3.1
>>
> Patch otherwise ok.
Hi Mark,
      thanks a lot.
      update the above two questions you mentioned.
> Thanks,
>
> - Mark
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

-------------- next part --------------
From ce4bcaf1cf4010bb5ad9ff97d6df803a629d2e88 Mon Sep 17 00:00:00 2001
From: Zhengxu <zhengxu.maxwell at gmail.com>
Date: Thu, 5 Jan 2017 14:48:06 +0800
Subject: [PATCH] ffmpeg_qsv: Add an option "qsv_device" to choose an proper
 node for QSV child device(vaapi or dxva2).

Reason: For some cases, such as 2 or more graphics card existing, the
default command line may fail because ffmpeg open a wrong device node:
    ffmpeg -hwaccel qsv -c:v h264_qsv -i test.264 -c:v h264_qsv out.264
Let user to choose the proper one by running like below:
    ffmpeg -hwaccel qsv -qsv_device /dev/dri/renderD128 -c:v h264_qsv \
-i test.264 -c:v h264_qsv out.264

Signed-off-by: ChaoX A Liu <chaox.a.liu at gmail.com>
Signed-off-by: Huang, Zhengxu <zhengxu.maxwell at gmail.com>
Signed-off-by: Andrew, Zhang <huazh407 at gmail.com>
---
 ffmpeg.h     |  3 +++
 ffmpeg_opt.c |  5 +++++
 ffmpeg_qsv.c | 19 ++++++++++++++++---
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/ffmpeg.h b/ffmpeg.h
index ebe5bf0..081913b 100644
--- a/ffmpeg.h
+++ b/ffmpeg.h
@@ -602,6 +602,9 @@ extern const OptionDef options[];
 extern const HWAccel hwaccels[];
 extern int hwaccel_lax_profile_check;
 extern AVBufferRef *hw_device_ctx;
+#if CONFIG_QSV
+extern char *qsv_device;
+#endif
 
 
 void term_init(void);
diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c
index 6862456..52c2bab 100644
--- a/ffmpeg_opt.c
+++ b/ffmpeg_opt.c
@@ -3679,5 +3679,10 @@ const OptionDef options[] = {
         "set VAAPI hardware device (DRM path or X11 display name)", "device" },
 #endif
 
+#if CONFIG_QSV
+    { "qsv_device", HAS_ARG | OPT_STRING | OPT_EXPERT, { &qsv_device },
+        "set QSV hardware device (DirectX adapter index, DRM path or X11 display name)", "device"},
+#endif
+
     { NULL, },
 };
diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c
index 68ff5bd..86824b6 100644
--- a/ffmpeg_qsv.c
+++ b/ffmpeg_qsv.c
@@ -28,6 +28,8 @@
 
 #include "ffmpeg.h"
 
+char *qsv_device = NULL;
+
 static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
 {
     InputStream *ist = s->opaque;
@@ -44,15 +46,26 @@ static void qsv_uninit(AVCodecContext *s)
 static int qsv_device_init(InputStream *ist)
 {
     int err;
+    AVDictionary *dict = NULL;
+
+    if (qsv_device) {
+        err = av_dict_set(&dict, "child_device", qsv_device, 0);
+        if (err < 0)
+            return err;
+    }
 
     err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV,
-                                 ist->hwaccel_device, NULL, 0);
+                                 ist->hwaccel_device, dict, 0);
     if (err < 0) {
         av_log(NULL, AV_LOG_ERROR, "Error creating a QSV device\n");
-        return err;
+        goto err_out;
     }
 
-    return 0;
+err_out:
+    if (dict)
+        av_dict_free(&dict);
+
+    return err;
 }
 
 int qsv_init(AVCodecContext *s)
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list