1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-02-09 14:14:39 +02:00

ffmpeg: Add an option "qsv_device" to choose proper node for QSV child device (vaapi or dxva2)

Reason: For some cases, such as 2 or more graphics cards existing, the
default command line may fail because ffmpeg does not open the correct
device node:
    ffmpeg -hwaccel qsv -c:v h264_qsv -i test.264 -c:v h264_qsv out.264
Let user 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@gmail.com>
Signed-off-by: Huang, Zhengxu <zhengxu.maxwell@gmail.com>
Signed-off-by: Andrew, Zhang <huazh407@gmail.com>
Signed-off-by: Mark Thompson <sw@jkqxz.net>
This commit is contained in:
Zhengxu 2017-01-05 14:48:06 +08:00 committed by Mark Thompson
parent f55da2200d
commit 1a79b8f8d2
3 changed files with 27 additions and 6 deletions

View File

@ -602,6 +602,9 @@ extern const OptionDef options[];
extern const HWAccel hwaccels[]; extern const HWAccel hwaccels[];
extern int hwaccel_lax_profile_check; extern int hwaccel_lax_profile_check;
extern AVBufferRef *hw_device_ctx; extern AVBufferRef *hw_device_ctx;
#if CONFIG_QSV
extern char *qsv_device;
#endif
void term_init(void); void term_init(void);

View File

@ -3679,5 +3679,10 @@ const OptionDef options[] = {
"set VAAPI hardware device (DRM path or X11 display name)", "device" }, "set VAAPI hardware device (DRM path or X11 display name)", "device" },
#endif #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, }, { NULL, },
}; };

View File

@ -28,6 +28,8 @@
#include "ffmpeg.h" #include "ffmpeg.h"
char *qsv_device = NULL;
static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags) static int qsv_get_buffer(AVCodecContext *s, AVFrame *frame, int flags)
{ {
InputStream *ist = s->opaque; InputStream *ist = s->opaque;
@ -44,15 +46,26 @@ static void qsv_uninit(AVCodecContext *s)
static int qsv_device_init(InputStream *ist) static int qsv_device_init(InputStream *ist)
{ {
int err; int err;
AVDictionary *dict = NULL;
err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV, if (qsv_device) {
ist->hwaccel_device, NULL, 0); err = av_dict_set(&dict, "child_device", qsv_device, 0);
if (err < 0) { if (err < 0)
av_log(NULL, AV_LOG_ERROR, "Error creating a QSV device\n"); return err;
return err;
} }
return 0; err = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_QSV,
ist->hwaccel_device, dict, 0);
if (err < 0) {
av_log(NULL, AV_LOG_ERROR, "Error creating a QSV device\n");
goto err_out;
}
err_out:
if (dict)
av_dict_free(&dict);
return err;
} }
int qsv_init(AVCodecContext *s) int qsv_init(AVCodecContext *s)