From patchwork Thu May 3 01:20:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 8750 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp1251655jad; Wed, 2 May 2018 18:20:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqukjomTkuYXoQVe3Xa9jytab4l5gEsW3t06Ea8YdSSIclXG0OJshwlbhiJLvEz200zrMa3 X-Received: by 10.28.131.211 with SMTP id f202mr13515098wmd.20.1525310427447; Wed, 02 May 2018 18:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525310427; cv=none; d=google.com; s=arc-20160816; b=DSp1tX62cf+PRQN9MbcFUdcUfZgb+V8YVytOa4tIUyxxloVE4YSvjDXpTRW9FF4PpA Yh6eP+Nr22kMM9I3vznehv9VqHaajPnV/+xbnXi3NGcVRYhkR5TDGWt2G0hKE1yUPAhV egzMdqISLdh67/v+F73FnXkQCdoFiPCVguHgtCtKpMvjlrGOPveGS/tYihsQ3LaOWyc6 Ed+BF/UxjpusnKijM3pmIVFGEujH8FD8z+C+uHZf0vQsPpDnVgXS5gjoSepuYIccjZOW Dx4lD/AbGLVOMkfbeCqJlZt9lczXHl648WZfSK/gpDRVr30MlLJcOyRnQMz6RkY5UHas oGPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:dkim-signature:delivered-to :arc-authentication-results; bh=6H8g2H0xCwzzJUQGGRU6sb0CNX6rz69Q0z5upgVuJoI=; b=jgy+Itw0hjDCFS8zzpDYHIkBVY9nx9afhYVkzYMPhX4n1BDFdnEMS+drhtbXT+fg9P Nzy2KTaDMKfda2Izcql867nF/7+NZz1JudHIlChdGuKNAVaA423RvvVxdFzF6PswT4t2 E6aEfAjOJI5FvTev8/82hlGfTN86hyGqWnmWMuKmFQgo1/VxBokholYggps62D3bLfuR 12bltztGGSH4HOw+36pGYK4wMWj9HgmDAkkECNn4djvqwe390mEU7HVNAaRfN30FHqGU e9dOaxDhKSNzx3hyq+u4jm5zzyuk677F/dhP7CaZyZV6pUh9U+Wx01KjXZUc8U5luC6/ DrBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=BuCpNGvc; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m10-v6si11207158wrh.458.2018.05.02.18.20.26; Wed, 02 May 2018 18:20:27 -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=@gmail.com header.s=20161025 header.b=BuCpNGvc; 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=QUARANTINE 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 3E84068A4F4; Thu, 3 May 2018 04:19:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 53B1F68A4B6 for ; Thu, 3 May 2018 04:19:46 +0300 (EEST) Received: by mail-wm0-f52.google.com with SMTP id n10so27323951wmc.1 for ; Wed, 02 May 2018 18:20:19 -0700 (PDT) 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:content-language; bh=LucQ9N1iBBToBtcJgvxM+G/WuQCrUGzDFJh4fo08qis=; b=BuCpNGvcEMvoG2BzErXk5rPVQLMTurpp5Wl761av6IFJ+areBwwHhSL8M3wwNdVMpV XR5WE5Fosx675c/9FU7CD49AoWdvuW/YIOC58JqCDIWqqprMwqZj3FmH1V54t+6k6v8e 79bU2Qf04ANA0xeJFsbSJprDQ2sxv/T6cCq/tAJ/I3ds/gYaIIiAnAVaZFueLO2LATGO Ychiluryy7Lwm0zmVWZ/Kv6kBfmvVdRnwJ9K0rcJZudGComZxhTAVpfl+20k2EiYKf3T jfdbx4ITByow3TaerD+t9adqXXmwcx+GkZpcWhN0/FQ3hPJY6PSsJF8BJJSmA/c4amsz 2+wA== 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:content-language; bh=LucQ9N1iBBToBtcJgvxM+G/WuQCrUGzDFJh4fo08qis=; b=MY4oPIIrc51vkJOLGlA8LAfOVC7Q7zqJxZyyMZQrbEpBulsDaUOTx54mdvgXCdyqJG +cOLYYloKwZvGxP2+SJpT1jJnJEDj2wHbrF4BkMsupb7R2nsSXxO0XxX1eHx47fcu2/U 33I+0KGkIQ7sTSFITkqqROxzOMeTkwWgCiokGpzjoHWFbxhfGB+jKIsXsy5ZgiWUR0GX 6Ly8DvjTw62vnq9i7lAeH4p6gHFCThiVCstgViXaZ89QgPQjgwuO1XqFBLiWNDXvaLl2 OtqT3UisWIJ6uP+tyQK+JkTbhtmdSdJDDa4mOOfnavTfiPzNmUE2hFjOur1UR7XdrLjt yeCQ== X-Gm-Message-State: ALQs6tBvjxWzcsbVmoIkm4PWWQqsC0T+2eUNhX45DQLpWf+ciuzsJ7ry RlB4Yfld2uj9BcqPq8Hg6OB5ZQ== X-Received: by 2002:a50:a107:: with SMTP id 7-v6mr22914440edj.280.1525310418428; Wed, 02 May 2018 18:20:18 -0700 (PDT) Received: from [192.168.0.101] (176-159-7-188.abo.bbox.fr. [176.159.7.188]) by smtp.googlemail.com with ESMTPSA id e24-v6sm7399265edc.80.2018.05.02.18.20.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 May 2018 18:20:17 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <424831b2-1616-bbb8-cd76-60f6ff26b87b@gmail.com> <1e0bf32d-3110-9c5c-537f-c27facde19ca@rothenpieler.org> From: "pkv.stream" Message-ID: Date: Thu, 3 May 2018 03:20:10 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <1e0bf32d-3110-9c5c-537f-c27facde19ca@rothenpieler.org> Content-Language: fr Subject: Re: [FFmpeg-devel] [PATCH v2]avocdec/nvenc: Reconfigure bitrate on the fly 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" Le 03/05/2018 à 12:21 AM, Timo Rothenpieler a écrit : >> Hi >> thanks for your feedback. >> I was not sure of whether to put the capability check with the others >> in nvenc_check_capabilities because if the cap is missing this would >> remove the encoder altogether: >> >> ex: ln. 453 :     if ((ret = nvenc_check_capabilities(avctx)) < 0) >>                          goto fail3; >> >> I'll move it there then or if you think it's preferrable, I can move >> it to ff_nvenc_encode_init and store it. >> Which option do you prefer ? I'll resubmit and rebase once the other >> patch is committed. > > Just add a new field to the struct NvencContext. done > And there is no need to fail on this check, store its result and go > on, unless it's < 0, which indicates an actual error. done > > There's also no need to check for a changed bitrate outside of the > call to reconfig_encoder, when making the same check inside of it again. > > done I have also removed per your suggestion the bitrate settings rc_min_rate and rc_max_rate to avctx->bit_rate; I added a check for CQP rc so that the encoder Reconfigure happens only if rc is not CQP. Thanks From 699b858f47ed9fa29b89816e5a5066abd2712610 Mon Sep 17 00:00:00 2001 From: pkviet Date: Thu, 3 May 2018 02:15:52 +0200 Subject: [PATCH] avcodec/nvenc: Enable dynamic bitrate The patch enables dynamic bitrate through ReconfigureEncoder method from nvenc API. This is useful for live streaming in case of network congestion. Signed-off-by: pkviet --- libavcodec/nvenc.c | 19 +++++++++++++++++-- libavcodec/nvenc.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 3313c376fe..38d755ada8 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -550,6 +550,10 @@ static av_cold int nvenc_setup_device(AVCodecContext *avctx) av_log(avctx, AV_LOG_FATAL, "Provided device doesn't support required NVENC features\n"); return ret; } + ctx->dynamic_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE); + if (!ctx->dynamic_bitrate) { + av_log(avctx, AV_LOG_VERBOSE, "Dynamic Encode bitrate change not supported\n"); + } } else { int i, nb_devices = 0; @@ -1951,8 +1955,20 @@ static int reconfig_encoder(AVCodecContext *avctx, const AVFrame *frame) params.reInitEncodeParams.darHeight = dh; params.reInitEncodeParams.darWidth = dw; + ctx->init_encode_params.darHeight = dh; + ctx->init_encode_params.darWidth = dw; + needs_reconfig = 1; + } + if (ctx->dynamic_bitrate > 0 && ctx->rc != NV_ENC_PARAMS_RC_CONSTQP + && ctx->encode_config.rcParams.averageBitRate != avctx->bit_rate) { + params.version = NV_ENC_RECONFIGURE_PARAMS_VER; + params.resetEncoder = 1; + params.forceIDR = 1; + params.reInitEncodeParams = ctx->init_encode_params; + params.reInitEncodeParams.encodeConfig->rcParams.averageBitRate = avctx->bit_rate; needs_reconfig = 1; + needs_encode_config = 1; } if (!needs_encode_config) @@ -1963,8 +1979,7 @@ static int reconfig_encoder(AVCodecContext *avctx, const AVFrame *frame) if (ret != NV_ENC_SUCCESS) { nvenc_print_error(avctx, ret, "failed to reconfigure nvenc"); } else { - ctx->init_encode_params.darHeight = dh; - ctx->init_encode_params.darWidth = dw; + av_log(avctx, AV_LOG_INFO, "nvencReconfigureEncoder succeeded\n"); } } diff --git a/libavcodec/nvenc.h b/libavcodec/nvenc.h index c7506d6a15..fd2350aaa6 100644 --- a/libavcodec/nvenc.h +++ b/libavcodec/nvenc.h @@ -184,6 +184,7 @@ typedef struct NvencContext int weighted_pred; int coder; int b_ref_mode; + int dynamic_bitrate; } NvencContext; int ff_nvenc_encode_init(AVCodecContext *avctx);