From patchwork Sun Jun 18 23:27:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philip Langdale X-Patchwork-Id: 4032 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.22.4 with SMTP id 4csp667674vsw; Sun, 18 Jun 2017 16:38:19 -0700 (PDT) X-Received: by 10.28.130.196 with SMTP id e187mr14186048wmd.24.1497829098938; Sun, 18 Jun 2017 16:38:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497829098; cv=none; d=google.com; s=arc-20160816; b=rO4A9RxTlIDc9HnIvjm3GY7YzS4lC7Ou/MMTIRGUTiDPpQj1bMHpBZhjX9slyK/mGD EUjOMr/8B2dXZKa5+1IvFDcKmkGUE559h+oR/bQ2c5c3lsUiBh5OG30m9TACHmmvpmtf nLhRR0id6uQziecwypxVklcoXXlqAHw3SXOjKLa5Owb61oJcmCAcA2ds5KCN4hm//wZ6 cooMifCgg2cOLloJGV5ypmO3s/iiPFiswDkmmJk5qRrjLhayJbo6xnn6naZ1rKZbMG85 Yayt2KtBzvq2UO2swUBV8yzLb/t1kX9+lRXFg4RAfMnD9DWjZJMORAUoFd1vpOB4tjEb UR9g== 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=UCQoG6bEOPiENHEgxiFqJ2odOhjYGheHYc9btZSAK9g=; b=gVpH/r1BAhOlHJ90RUFLDg6t4NxRMvUiMy7U4HAOziySs63r0Och1LOUy/8S+w2c66 yVBze/P3A6pT8npL9n/Twk/JZ1X/PfQ3p7B1SYUjTOXCQNWDaAQBIo5Yf2+csefaPcK+ lozLrBYw/DI0PL8rzcp1rD+FavMT4jy+barCnNrmsE3hoFtvvySztem8/C57IO+ievaC ii3RJpcvcNoDrI2n7KZycoA7iav9lfJ/P5zKLBPXHXePKE8jNrSgh1WfUmWEFJ9/mWX7 5KS1gng+biOMvqwtHrR1NQPdUpFkrW7ozCix/3GkkqfowekEEux8/9x839KxE7YUYWV8 8B4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@overt.org header.b=NBlm9XcT; dkim=neutral (body hash did not verify) header.i=@overt.org header.b=OvBQdhi5; 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 z192si4872844wme.173.2017.06.18.16.38.18; Sun, 18 Jun 2017 16:38:18 -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=NBlm9XcT; dkim=neutral (body hash did not verify) header.i=@overt.org header.b=OvBQdhi5; 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 9A59A68A1E5; Mon, 19 Jun 2017 02:37:55 +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 8563E68A0F0 for ; Mon, 19 Jun 2017 02:37:48 +0300 (EEST) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=overt.org; q=dns/txt; s=k1; t=1497829071; h=References: In-Reply-To: Message-Id: Date: Subject: Cc: To: From: Sender; bh=QFJyIRDWStbJbOX43Yx8UIkBPtmoAJySH31+q9W+1Zw=; b=NBlm9XcTvjludzna5QR7mEoA+XEp4AqHtLCbEGa0hHp1dzWv3WGTeKwry9qGHJTjd7dRr/k6 XyueyboRMBw4IL5HAjgoNTEfiLf6Q2iTfJyuGu5sAWRiVbRCHmmxf0IukYeVpEh2ygVTB3jJ i38E1CtfQPIA7KLSWtryXrIn3Pk= 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=t/Qt8mFK1xaeZ3VsuLO7L2U0BC5Wq2wER97D/kcu6lKTCbxNt0w5McOv9E1lo/EBMwwZ5t hkTwFSCK5sY6Ai/SVkFw75kP4p1VHzlU1O26WmVgp2WazWO7gLMqD0UmLRTRPRmQ03022gvy WDZdzl8LKyNqRCeSnbS3pQWR+aGes= 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 59470c6f.7f60603c9a78-smtp-out-n02; Sun, 18 Jun 2017 23:27:43 -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 3D1FE60254; Sun, 18 Jun 2017 23:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=overt.org; s=mail; t=1497828462; bh=v9OlwVuG7AwsDSeJ2vKoCXisMxbIGq8y6WXvhdAMQ3U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OvBQdhi5DNzEEpTihMtkYfrJubNJkgsVJl1REfcD4gB/j8ifelFVhaHqnsR59AgKZ Hh4sLrao0c8XhoGociHvVa1gGqCV7AlcDKcYanK9I+UksxXrl09w/Ecd3Waa+HqBSp Q+PGALUmNfDF+9EQdnnqXwD2B3TU9XKrmXcywL52k4grBdLtA7EGcG2Be+qddHK3Rb 6oOfwQsC+hoDbiRPERhIp3upI8bNobGbmHgT7yfhATv/1L8bxJBGF5gqEuBGZIw9MY HGbaSVch0s4W35ckbZanhb2GGLJErtqY/gg01nnm9hzG7HEvEe+/MTMPKTxhQP9MPe 8sWYqIQTMCQfQ== From: Philip Langdale To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Jun 2017 16:27:30 -0700 Message-Id: <20170618232730.14614-3-philipl@overt.org> In-Reply-To: <20170618232730.14614-1-philipl@overt.org> References: <20170618232730.14614-1-philipl@overt.org> Subject: [FFmpeg-devel] [PATCH 2/2] ffmpeg: Set default output format for cuvid 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" The cuvid hwaccel is weird because it's not a real hwaccel. This means that requesting the hwaccel by itself does nothing as the right decoder and encoder have to be request to take advantage of it. On the other hand, requesting the cuvid decoder or nvenc encoder will always be hardware accelerated because that's inherently what they are. The end result is that '-hwaccel cuvid' really ends up being an option that requests the use of a shared context that allows full hardware transcoding without copying frames back-and-forth to/from system memory. This differs from 'real' hwaccels, which plug into the existing decoders (and encoders?). In this case, the default format is controlled by the decoder/encoder and not the presence of the hwaccel. So, for example, with vaapi, the hardware will decode the video but it will be automatically converted to a software format in system memory unless the output format is explicitly set to the native hardware one. Switching cuvid to be a generic hwaccel brings this later behaviour to cuvid; specifying the hwaccel by itself without an output format does exactly nothing - the decoder and encoder continue to define their own contexts and frames pass through system memory. More importantly, this changes the behaviour of command lines that used to do full transcoding - a new argument must be added to specify the output format. To avoid breaking this compatibility, one possible solution is to allow an hwaccel to indicate that its default output format is its native hardware format, and that is what is implemented in this change. We believe that the qsv hwaccel also has the same pre-generic behaviour and could also be a candidate for this. Signed-off-by: Philip Langdale --- ffmpeg.h | 1 + ffmpeg_opt.c | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ffmpeg.h b/ffmpeg.h index fa81427471..6ea29ded11 100644 --- a/ffmpeg.h +++ b/ffmpeg.h @@ -76,6 +76,7 @@ typedef struct HWAccel { enum HWAccelID id; enum AVPixelFormat pix_fmt; enum AVHWDeviceType device_type; + int pix_fmt_is_default; } HWAccel; typedef struct HWDevice { diff --git a/ffmpeg_opt.c b/ffmpeg_opt.c index 6dc4ad43d2..b01dc0c895 100644 --- a/ffmpeg_opt.c +++ b/ffmpeg_opt.c @@ -68,31 +68,31 @@ const HWAccel hwaccels[] = { #if HAVE_VDPAU_X11 { "vdpau", hwaccel_decode_init, HWACCEL_VDPAU, AV_PIX_FMT_VDPAU, - AV_HWDEVICE_TYPE_VDPAU }, + AV_HWDEVICE_TYPE_VDPAU, 0 }, #endif #if HAVE_DXVA2_LIB { "dxva2", dxva2_init, HWACCEL_DXVA2, AV_PIX_FMT_DXVA2_VLD, - AV_HWDEVICE_TYPE_NONE }, + AV_HWDEVICE_TYPE_NONE, 0 }, #endif #if CONFIG_VDA { "vda", videotoolbox_init, HWACCEL_VDA, AV_PIX_FMT_VDA, - AV_HWDEVICE_TYPE_NONE }, + AV_HWDEVICE_TYPE_NONE, 0 }, #endif #if CONFIG_VIDEOTOOLBOX { "videotoolbox", videotoolbox_init, HWACCEL_VIDEOTOOLBOX, AV_PIX_FMT_VIDEOTOOLBOX, - AV_HWDEVICE_TYPE_NONE }, + AV_HWDEVICE_TYPE_NONE, 0 }, #endif #if CONFIG_LIBMFX { "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV, - AV_HWDEVICE_TYPE_NONE }, + AV_HWDEVICE_TYPE_NONE, 0 }, #endif #if CONFIG_VAAPI { "vaapi", hwaccel_decode_init, HWACCEL_VAAPI, AV_PIX_FMT_VAAPI, - AV_HWDEVICE_TYPE_VAAPI }, + AV_HWDEVICE_TYPE_VAAPI, 0 }, #endif #if CONFIG_CUVID { "cuvid", hwaccel_decode_init, HWACCEL_CUVID, AV_PIX_FMT_CUDA, - AV_HWDEVICE_TYPE_CUDA }, + AV_HWDEVICE_TYPE_CUDA, 1 }, #endif { 0 }, }; @@ -708,6 +708,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) char *discard_str = NULL; const AVClass *cc = avcodec_get_class(); const AVOption *discard_opt = av_opt_find(&cc, "skip_frame", NULL, 0, 0); + enum AVPixelFormat default_pix_fmt = AV_PIX_FMT_NONE; if (!ist) exit_program(1); @@ -805,6 +806,8 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) for (i = 0; hwaccels[i].name; i++) { if (!strcmp(hwaccels[i].name, hwaccel)) { ist->hwaccel_id = hwaccels[i].id; + if (hwaccels[i].pix_fmt_is_default) + default_pix_fmt = hwaccels[i].pix_fmt; break; } } @@ -837,7 +840,7 @@ static void add_input_streams(OptionsContext *o, AVFormatContext *ic) "format: %s", hwaccel_output_format); } } else { - ist->hwaccel_output_format = AV_PIX_FMT_NONE; + ist->hwaccel_output_format = default_pix_fmt; } ist->hwaccel_pix_fmt = AV_PIX_FMT_NONE;