From patchwork Tue Jun 29 01:45:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 28727 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5d:965a:0:0:0:0:0 with SMTP id d26csp2457781ios; Mon, 28 Jun 2021 18:46:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQ5j3HxPMiNbVU+86lTozNYjYtRHXAFa+kXfvkEjVrTkCP01Ey4gpW1a1ouLDhJ07BR9tq X-Received: by 2002:a05:6402:54c:: with SMTP id i12mr36639656edx.64.1624931160351; Mon, 28 Jun 2021 18:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624931160; cv=none; d=google.com; s=arc-20160816; b=tc7havlQ15l3WCOWDwX/x8roQLYIqL3ys1sr40EcxMFsdTTUMPihbVew7n4RtNmg5o K6sFYFBskpXTfJzG36kLi3fl9rwA41cCiG9jvoswzLvnBXun1EFl462BOPWwcugm+KQJ j/xhptATy2J+W886iz/8TSmwTq/X24F1Ez9FORCehTuCR0eJj+EvMGc18H0rD2F3LPD4 nqmVC5+p7dtigZmDIwaT6e1VZs6SCrNdt7eTFSAbXh93v36Y0Q+FlMdiAxf7TF+LVg9n /HavggsHKGoVOuTLJQzOimouZgQpyJw0jI1ishEGEcBkyLGEQ+Yh9VPXBEAuEPaafGpZ W2nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=ROyn3Ba+EFGicPlctaDeGkbVVZLlWHPnQdiPaEH2pWE=; b=fFEHoS0BghjD/ucT7T+ko88LfUBQ0P7pxqG4gcU6GYQ0YQWWe/qAFU7mOY1zjd0dG0 Od91HLoCwhRuaqDdWRw6wyMC31g3MzGwMYz2Mp32TPAwwyRTmmijzRBKlJaDCPA2v5Xg TD3NWyQP6y0oCy/Qov1WYpvUs7ZMGpMe4i/DIYPDw1Pev2CkmQa6bW2x6a0dqDvOj4s1 bQHV4usVNqVX8zGa5SaC3Vy6tIzT2TiVGOS+27Rn/RY4sUeh5fEgalCGSmq93aCVGAOS E4IOpSto6Po2vNERRes+/aJnmvrE+4bN2D6ki+CKXWuixqe6wAIEMf5C+0CAL01sAzKQ OQtg== ARC-Authentication-Results: i=1; mx.google.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 sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s21si10790182ejy.697.2021.06.28.18.45.59; Mon, 28 Jun 2021 18:46:00 -0700 (PDT) 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; 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 sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4BD1068A2B2; Tue, 29 Jun 2021 04:45:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 10E3F68A2B2 for ; Tue, 29 Jun 2021 04:45:47 +0300 (EEST) X-IronPort-AV: E=McAfee;i="6200,9189,10029"; a="205059265" X-IronPort-AV: E=Sophos;i="5.83,307,1616482800"; d="scan'208";a="205059265" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jun 2021 18:45:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,307,1616482800"; d="scan'208";a="492527336" Received: from xhh-tgl64.sh.intel.com ([10.239.159.53]) by fmsmga002.fm.intel.com with ESMTP; 28 Jun 2021 18:45:41 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Tue, 29 Jun 2021 09:45:38 +0800 Message-Id: <20210629014538.3065929-1-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] ffmpeg_hw: make hardware selection for filters more user friendly X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: WhLIk/7QXMsI When a device is derived from a source device, there are at least 2 devices, and usually the derived device is the expected device, so let's pick the last device if user doesn't specify the filter device with filter_hw_device option After applying this patch, the command below can work: $> ffmpeg -init_hw_device vaapi=va:/dev/dri/renderD128 -init_hw_device qsv=hw@va -f lavfi -i yuvtestsrc -vf format=nv12,hwupload=extra_hw_frames=64 -c:v h264_qsv -y out.h264 --- fftools/ffmpeg_hw.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/fftools/ffmpeg_hw.c b/fftools/ffmpeg_hw.c index fc4a5d31d6..14e2cb0177 100644 --- a/fftools/ffmpeg_hw.c +++ b/fftools/ffmpeg_hw.c @@ -527,15 +527,21 @@ int hw_device_setup_for_filter(FilterGraph *fg) HWDevice *dev; int i; - // If the user has supplied exactly one hardware device then just - // give it straight to every filter for convenience. If more than - // one device is available then the user needs to pick one explcitly - // with the filter_hw_device option. + // Pick the last hardware device if the user doesn't pick the device for + // filters explicitly with the filter_hw_device option. if (filter_hw_device) dev = filter_hw_device; - else if (nb_hw_devices == 1) - dev = hw_devices[0]; - else + else if (nb_hw_devices > 0) { + dev = hw_devices[nb_hw_devices - 1]; + + if (nb_hw_devices > 1) + av_log(NULL, AV_LOG_WARNING, "There are %d hardware devices. device " + "%s of type %s is picked for filters by default. Set hardware " + "device explicitly with the filter_hw_device option if device " + "%s is not usable for filters.\n", + nb_hw_devices, dev->name, + av_hwdevice_get_type_name(dev->type), dev->name); + } else dev = NULL; if (dev) {