From patchwork Fri Jan 6 06:37:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Huang, Zhengxu" X-Patchwork-Id: 2073 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp5703497vsb; Thu, 5 Jan 2017 22:37:52 -0800 (PST) X-Received: by 10.28.31.23 with SMTP id f23mr2073864wmf.94.1483684672033; Thu, 05 Jan 2017 22:37:52 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ey12si88231392wjc.243.2017.01.05.22.37.51; Thu, 05 Jan 2017 22:37:51 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DBED668A1D8; Fri, 6 Jan 2017 08:37:43 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 16600689201 for ; Fri, 6 Jan 2017 08:37:37 +0200 (EET) Received: by mail-pf0-f196.google.com with SMTP id 127so19493245pfg.0 for ; Thu, 05 Jan 2017 22:37:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to; bh=u86qIeArdw56m5hdEiEaiLnmzCPgAmf0CWq4AUcMd68=; b=FI/r+VHzK+EZpwZbKY9jVpnfA/e1p2PHfbRPXyQ7Ea5sVvmdq9z8ZG4CRljoQAia9R IlmLxXgdGUNbV86uAXcH6zANnZo4Ih8aMHLcsj0ZPrTAmtwdUut0ZeoSw/Zz193XDeIg QQtqEDm2oqs1rgL/7q7AVVSfwz/GvmFTpQvkmONgK4N+LgkUmjUDTeAAZQJJJhjsPc+J lyJiFaV7+KvN4ll3xAk8Dybs1qj90b8+zL1M3QSo0kMU7Z8SyXJ/82UOgH1833I9ERr7 CYXwnrXmr3ClsUmMKJxjRoVr04Sze7s5wFQDSbtkantE7h2YTHXrtTKNvlQvQwE1OFFd cDow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to; bh=u86qIeArdw56m5hdEiEaiLnmzCPgAmf0CWq4AUcMd68=; b=JN6BQCIdUa+tLnyuIMUFra9RE1osDSz7+euBkcGZ5RwPlTFpV8VGJNtQa7VzQFrlEO 13U/Fp6PNeT1KqZZHNNIjDMBcT2HZzt3LrBYAVqNs6mVnarmXfJCaF2gY5roNYdgwJVu Ssp/7xzUlx0pQBPCVrWjxgDrIwZAY71TcdzuuI96tgTkJKjxZIkMBbY18+IYo6JegVVb aUCiYeGQK8mJJ8ntCrD9ns/fzYKkoA158tADyHHnForVYJ0z2Jt+4bkWoDEEHpt8+UGY x5vZNWn7izhPlJ4RjPlJqpOJn0VFK1N+dTfLbhvi6DQKwzlwWyVcyWVztGnA2vaU502k MJbg== X-Gm-Message-State: AIkVDXKqS12wKUN2kc+CZ7Djq5jVcgheDeDZ/Cwxeogof3379V0hkbQDuoiU/VydNR8sYA== X-Received: by 10.84.192.1 with SMTP id b1mr163956461pld.113.1483684661400; Thu, 05 Jan 2017 22:37:41 -0800 (PST) Received: from [10.239.205.12] ([192.55.54.44]) by smtp.gmail.com with ESMTPSA id y73sm157458088pfa.68.2017.01.05.22.37.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Jan 2017 22:37:40 -0800 (PST) To: FFmpeg development discussions and patches , sw@jkqxz.net References: <36c9435d-86fe-f643-9fed-65712b6b697a@jkqxz.net> From: "Huang, Zhengxu" Message-ID: <9325ca81-197c-7598-44a6-506e9345852a@gmail.com> Date: Fri, 6 Jan 2017 14:37:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: <36c9435d-86fe-f643-9fed-65712b6b697a@jkqxz.net> Subject: Re: [FFmpeg-devel] [PATCH] libavutil/hwcontext_qsv: Command line using hwaccel 'QSV' doesn't work X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi According to the suggestion update the patch. thanks. 在 2017/1/3 21:14, Mark Thompson 写道: > On 03/01/17 07:13, Huang, Zhengxu wrote: >> From 687ce9c804b2618f021100235c46a33b48fa522c Mon Sep 17 00:00:00 2001 >> From: Zhengxu >> Date: Wed, 14 Dec 2016 11:55:31 +0800 >> Subject: [PATCH] libavutil/hwcontext_qsv: Command line using hwaccel 'QSV' >> doesn't work. >> >> Command: ffmpeg -hwaccel qsv -c:v h264_qsv -i test.264 -c:v h264_qsv out.264 >> >> Reason: hwcontext_qsv will create a child hwcontext_vaapi. VAAPI will >> open X11 display ":0.0" defaultly. However, MSDK doesn't support X11 so >> far. This results in the failure of this command. >> >> Fix: When using VAAPI, let VAAPI try to create DRM display handle by scanning >> device nodes under '/dev/dri/'. > We already default to attempting to open the first render node inside hwcontext_vaapi (if opening via X11 fails): > > http://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavutil/hwcontext_vaapi.c;h=6176bdc880c81dec7cac0b214a8d55f3b1160abc;hb=HEAD#l936 > > I think if you want this behaviour it would be better to add code there rather than in hwcontext_qsv (which doesn't really care about this aspect at all, it just wants a usable subdevice for the platform). > > Can you explain your case which hits this? Do you have some other external graphics card(s) along with the on-chip Intel graphics? For that case, I don't like the idea of scanning for a device node because it is perfectly possible to get a valid VADisplay handle for a non-QSV device (an AMD or Nvidia card with mesa, most obviously) which will then fail opaquely later when libmfx tries to use it because the Intel proprietary driver is required. This may even fail randomly, because device nodes associated with independent drivers are not ordered. > >> Signed-off-by: ChaoX A Liu >> Signed-off-by: Huang, Zhengxu >> Signed-off-by: Andrew, Zhang >> --- >> libavutil/hwcontext_qsv.c | 44 +++++++++++++++++++++++++++++++------------- >> 1 file changed, 31 insertions(+), 13 deletions(-) >> >> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c >> index 2dc9aca..2701b5a 100644 >> --- a/libavutil/hwcontext_qsv.c >> +++ b/libavutil/hwcontext_qsv.c >> @@ -707,12 +707,41 @@ static mfxIMPL choose_implementation(const char *device) >> return impl; >> } >> >> +static int create_proper_child_device(AVBufferRef **ctx, const char *device, int flags) >> +{ >> + enum AVHWDeviceType child_device_type; >> + char adapter[256]; >> + int adapter_num; >> + >> + if (CONFIG_VAAPI) >> + child_device_type = AV_HWDEVICE_TYPE_VAAPI; >> + else if (CONFIG_DXVA2) >> + child_device_type = AV_HWDEVICE_TYPE_DXVA2; >> + else >> + return AVERROR(ENOSYS); >> + >> + if (device || CONFIG_DXVA2) >> + return av_hwdevice_ctx_create(ctx, child_device_type, device, NULL, flags); >> + >> + for (adapter_num = 0; adapter_num < 6; adapter_num++) { >> + if (adapter_num < 3) >> + snprintf(adapter,sizeof(adapter), >> + "/dev/dri/renderD%d", adapter_num+128); >> + else >> + snprintf(adapter,sizeof(adapter), >> + "/dev/dri/card%d", adapter_num-3); > I would prefer not to open the DRM master device (/dev/dri/card*) by default - until very recent kernels it was exclusive-access-only, so nothing else can use the graphics at the same time (most obviously another ffmpeg instance). > >> + if (av_hwdevice_ctx_create(ctx, child_device_type, adapter, NULL, flags) == 0) >> + return 0; >> + } >> + >> + return AVERROR(ENOSYS); >> +} >> + >> static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, >> AVDictionary *opts, int flags) >> { >> AVQSVDeviceContext *hwctx = ctx->hwctx; >> QSVDevicePriv *priv; >> - enum AVHWDeviceType child_device_type; >> AVDictionaryEntry *e; >> >> mfxVersion ver = { { 3, 1 } }; >> @@ -730,18 +759,7 @@ static int qsv_device_create(AVHWDeviceContext *ctx, const char *device, >> ctx->free = qsv_device_free; >> >> e = av_dict_get(opts, "child_device", NULL, 0); >> - >> - if (CONFIG_VAAPI) >> - child_device_type = AV_HWDEVICE_TYPE_VAAPI; >> - else if (CONFIG_DXVA2) >> - child_device_type = AV_HWDEVICE_TYPE_DXVA2; >> - else { >> - av_log(ctx, AV_LOG_ERROR, "No supported child device type is enabled\n"); >> - return AVERROR(ENOSYS); >> - } >> - >> - ret = av_hwdevice_ctx_create(&priv->child_device_ctx, child_device_type, >> - e ? e->value : NULL, NULL, 0); >> + ret = create_proper_child_device(&priv->child_device_ctx, e ? e->value : NULL, 0); >> if (ret < 0) >> return ret; >> >> -- >> 1.8.3.1 >> > For your specific case in the ffmpeg utility it might be best to add a new command-line option (-qsv_device?) and then pass it as the "child_device" in the options dictionary? I admit this isn't necessarily helpful for other users, but it would fix your command above without running into the other problems above. > > Thanks, > > - Mark > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel From 4beadd3c84c797a56c4f375458d0a1e9d9b233c8 Mon Sep 17 00:00:00 2001 From: Zhengxu 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 Signed-off-by: ChaoX A Liu Signed-off-by: Huang, Zhengxu Signed-off-by: Andrew, Zhang --- 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"}, +#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;