From patchwork Sun Jun 25 21:27:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 4117 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp631926vsb; Sun, 25 Jun 2017 14:27:45 -0700 (PDT) X-Received: by 10.223.147.135 with SMTP id 7mr96450wrp.104.1498426065711; Sun, 25 Jun 2017 14:27:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498426065; cv=none; d=google.com; s=arc-20160816; b=WSAJP7UYPk8gNmQXaAozM/5Lv3KBT7M/vIPx7Snr/0THgrO9IZ9yOljkgME0MIXGo/ qc2uTyuyxjdpvK0uqidm1u8OxK4VOmMGotCUdzuKnuJX095G19ElRVdGPzAh5DK0lv9I aeGb/dAI1fAQf/h526okY7mZ8xjPINXP+tp3jeS08n6kpq+fcYB8VduC80dScqDlz3DV 9vOzn3E2mMt+z2jgbxEDWSINkAS9EAu1pPWLJaGeBQ87y54cX5cbZS/c3bBEWWO0UfCx cDc8YkCu7qg66Bpsipxa8G9di8ezSxBMZFaVEfc9pumWXLS/H8fWTTMC18f9RuTahtVW FnSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:domainkey-signature:dkim-signature :delivered-to:arc-authentication-results; bh=NLcGZER5RVXZm20eegi/f1DU8nTD91p3XH9UH3nDso8=; b=HTARbPf7DWXVx1bn7Tlt3qgcfTs8BexVHhha/qSYW0H3kQB5fTZQcgAdhqo9IG7KYK Ba28cxj9LIVt9Bwg2mpd7+lYa/jEoMPO6XHannDM6zRTGHLAtuDyQLXLijpBH2lzlgxh c/1eHCnsUwWYGibO7Rg66QL+LQrGciswbAKK+nUSS2e9d+R7z16CitXuvDZJZD0wo48x OatapR1weIkq0Z0tH2quUJNyyJBPkN51jxYONqr/jK9pASc64rxvM7tsNriBw8MmyLfg 2PwXlo2TshZ+y2iDIyGgYB4sDn4yzo3FA74UJ+rsyP85uNClxIzpVOxxBV97JVz/QDck +Eeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org header.b=pw8gf3Dc; dkim=neutral (body hash did not verify) header.i=@overt.org header.b=cOb4cD/M; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m143si9701762wmg.179.2017.06.25.14.27.45; Sun, 25 Jun 2017 14:27:45 -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; dkim=neutral (body hash did not verify) header.i=@overt.org header.b=pw8gf3Dc; dkim=neutral (body hash did not verify) header.i=@overt.org header.b=cOb4cD/M; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1A1B068A1F5; Mon, 26 Jun 2017 00:27:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-s67.mailgun.info (mail-s67.mailgun.info [184.173.153.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3589B680A9E for ; Mon, 26 Jun 2017 00:27:25 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=overt.org; q=dns/txt; s=k1; t=1498426044; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=vS2VnK1W0UOmhBqusHdX2lYbN61DNPkixY9DaMbV5ms=; b=pw8gf3Dc2ff+BhMc9ApLmJLKL9sAeSHWW/otWk2OU+jmT4tiTJ59krB7B3G9kc1hIaXY6nNR SsoMlGsjGi1Yrzmyji8y8K4Q/qulOWSqnbM7pHKFtYEMglPjyF8g7cxuMsJpS2RPLie9L+tc rL2/goDQ0kWqJ2rB81EdMFFlH2w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=overt.org; s=k1; q=dns; h=Sender: From: To: Cc: Subject: Date: Message-Id: In-Reply-To: References; b=ZGJ7HQC69RVF/L1yECupVceGv3yLYlCXPzefCHq/vO1bw94Et0BjsRlKD8izYl+LaXN+KA wTfFFSh3oeI23gTm9iaZARt8lKMVhJ8jE/F5MxB+rHbMpgXm9KuF8t6U7IGTrQaqo7SQfoA7 bvRdmAr+s7SVkgyd8p/ikQqzrpqcs= X-Mailgun-Sending-Ip: 184.173.153.195 X-Mailgun-Sid: WyIyM2Q3MCIsICJmZm1wZWctZGV2ZWxAZmZtcGVnLm9yZyIsICI0YTg5NjEiXQ== Received: from mail.overt.org (155.208.178.107.bc.googleusercontent.com [107.178.208.155]) by mxa.mailgun.org with ESMTP id 59502abc.7fc81820aea0-smtp-out-n03; Sun, 25 Jun 2017 21:27:24 -0000 (UTC) Received: from authenticated-user (mail.overt.org [107.178.208.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.overt.org (Postfix) with ESMTPSA id 84C296021F; Sun, 25 Jun 2017 21:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1498426043; bh=8avrc23ID8f7KqZWXXOFJO8jaKulUpvNAMggSiBMy/s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cOb4cD/M3dLziR5B4+ng8jdKEuYW5FoBbtSoYfRlVeZEMQSOpGK6qZmocRHvDtWzl 4LvqKr/UdvEueC+pIb9K/xNFZT+Jf44vPSag+fTIAaCUk0ZouNtha6WnCDIwFP9kFK HCN9xkR86x3lZn4d6WTgXwPaym3osMce3tMiyvl5t8TsWd5tAyL+LllJEKE/sLiXRb bUP8hIUCywUAn6ExHnRUjluymYuccAug3Zs4hkaJlm7dWupvP+k6vqNuSkLG10mKm6 KspcIWXdJMs/XBSCglCYgC3SpJP15RvqGeA0uvQYZJCpZsvqeo8vsrIAxQrrcvhEJN 2Bi8rcc4xPpqQ== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Jun 2017 14:27:05 -0700 Message-Id: <20170625212706.10384-2-philipl@overt.org> In-Reply-To: <20170625212706.10384-1-philipl@overt.org> References: <20170625212706.10384-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH 1/2] ffmpeg: Switch cuvid to generic hwaccel 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 Cc: Philip Langdale MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" With generic hwaccel, it is additionally necessary to specify the output format. If this is not done, we'll end up downloading the frames back and then re-uploading them. For example: ffmpeg -y -hwaccel cuvid -hwaccel_output_format cuda \ -c:v h264_cuvid -i sample.mp4 \ -c:v h264_nvenc -f rawvideo /dev/null Signed-off-by: Philip Langdale --- Makefile | 1 - ffmpeg.h | 1 - ffmpeg_cuvid.c | 73 ---------------------------------------------------------- ffmpeg_opt.c | 4 ++-- 4 files changed, 2 insertions(+), 77 deletions(-) delete mode 100644 ffmpeg_cuvid.c diff --git a/Makefile b/Makefile index aef18185d4..0766c3b719 100644 --- a/Makefile +++ b/Makefile @@ -37,7 +37,6 @@ OBJS-ffmpeg-$(CONFIG_LIBMFX) += ffmpeg_qsv.o ifndef CONFIG_VIDEOTOOLBOX OBJS-ffmpeg-$(CONFIG_VDA) += ffmpeg_videotoolbox.o endif -OBJS-ffmpeg-$(CONFIG_CUVID) += ffmpeg_cuvid.o OBJS-ffmpeg-$(HAVE_DXVA2_LIB) += ffmpeg_dxva2.o OBJS-ffserver += ffserver_config.o diff --git a/ffmpeg.h b/ffmpeg.h index c3854bcb4a..fa81427471 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -665,7 +665,6 @@ int dxva2_init(AVCodecContext *s); int vda_init(AVCodecContext *s); int videotoolbox_init(AVCodecContext *s); int qsv_init(AVCodecContext *s); -int cuvid_init(AVCodecContext *s); HWDevice *hw_device_get_by_name(const char *name); int hw_device_init_from_string(const char *arg, HWDevice **dev); diff --git a/ffmpeg_cuvid.c b/ffmpeg_cuvid.c deleted file mode 100644 index 3ff3b40f17..0000000000 --- a/ffmpeg_cuvid.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "libavutil/hwcontext.h" -#include "libavutil/pixdesc.h" - -#include "ffmpeg.h" - -static void cuvid_uninit(AVCodecContext *avctx) -{ - InputStream *ist = avctx->opaque; - av_buffer_unref(&ist->hw_frames_ctx); -} - -int cuvid_init(AVCodecContext *avctx) -{ - InputStream *ist = avctx->opaque; - AVHWFramesContext *frames_ctx; - int ret; - - av_log(avctx, AV_LOG_VERBOSE, "Initializing cuvid hwaccel\n"); - - if (!hw_device_ctx) { - ret = av_hwdevice_ctx_create(&hw_device_ctx, AV_HWDEVICE_TYPE_CUDA, - ist->hwaccel_device, NULL, 0); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA device\n"); - return ret; - } - } - - av_buffer_unref(&ist->hw_frames_ctx); - ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx); - if (!ist->hw_frames_ctx) { - av_log(avctx, AV_LOG_ERROR, "Error creating a CUDA frames context\n"); - return AVERROR(ENOMEM); - } - - frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data; - - frames_ctx->format = AV_PIX_FMT_CUDA; - frames_ctx->sw_format = avctx->sw_pix_fmt; - frames_ctx->width = avctx->width; - frames_ctx->height = avctx->height; - - av_log(avctx, AV_LOG_DEBUG, "Initializing CUDA frames context: sw_format = %s, width = %d, height = %d\n", - av_get_pix_fmt_name(frames_ctx->sw_format), frames_ctx->width, frames_ctx->height); - - ret = av_hwframe_ctx_init(ist->hw_frames_ctx); - if (ret < 0) { - av_log(avctx, AV_LOG_ERROR, "Error initializing a CUDA frame pool\n"); - return ret; - } - - ist->hwaccel_uninit = cuvid_uninit; - - return 0; -} diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index bb6001f534..6dc4ad43d2 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -91,8 +91,8 @@ const HWAccel hwaccels[] = { AV_HWDEVICE_TYPE_VAAPI }, #endif #if CONFIG_CUVID - { "cuvid", cuvid_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA, - AV_HWDEVICE_TYPE_NONE }, + { "cuvid", hwaccel_decode_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA, + AV_HWDEVICE_TYPE_CUDA }, #endif { 0 }, };