From patchwork Thu May 3 02:04:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "pkv.stream" X-Patchwork-Id: 8751 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:155:0:0:0:0:0 with SMTP id c82-v6csp1280269jad; Wed, 2 May 2018 19:04:57 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpgpCEICbB+/Yo15V8nP0onzvSB6JX/nQ9o8d2875o88tHHp5/h3TfXSJrGH6eSEsDXX9ds X-Received: by 2002:adf:c4c3:: with SMTP id o3-v6mr16443939wrf.108.1525313097065; Wed, 02 May 2018 19:04:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525313097; cv=none; d=google.com; s=arc-20160816; b=znnxoQ+LAT9GOvHMw+Lt2z4zw5KtVjD3+PvRNqZycHD4nx0qU8McqiiAjTwoeoAmE3 SPKY17bVqU6DZq3JUG9hGHCSFJ9m/rTYLOKUphB9JDce475vYXBienDSI0mBqdXrNXF7 2N6i8C5nEWWRY1u7Z//I9R0vW6EuCaJjedhNtWGTEu4dUTlWUm64tkq4dfrT2t0vhlgC Oww7HwgW9/Tf8R+6U1uKuv3XlAkt7gJHMQ/HKs8alnl6EuURuK9Gr1Jo+ElHNiSHpvym Fr7qL4SFlUhRYzyqIzShhICCYvYcEq5MyGbQksL4Ftkc3DCxLt1CA4NnYfgkV5lthCys KUWw== 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=vGyEbYEd+0i8J6u1v7DCopS+Uy5+x4fzi3B0W1WqfFA=; b=W4qeLRCsS98rZtGMqVWJ54hc7l8m2r4lOTzQRrxvZey0D1Of9WD4+I8zoC1/ESXNCz c/zVVq3CtgfIj1XvhXxRlMM4V1P+HRnezTdT957sqg8WVfOsLGtTNXXDSfJEsBnO182p PQM4G07aesAtmTCmKtEPgbZGuVDaJSlaLN2oqE0LSNwjx++0QhSBNpM9SJRioYegQb5+ Z3KVD+lrKfim5mCxUIZ587qCHhd/TdYm0S0hsWjuY9mrshmZmoKdTTdXiYZo9j2T/qmH BWscDxsyK6+qgy1R13EPTu8B9GQ0z768Deu4J7MaEzVCYYj9azckVVt5nlVqA9jtkNMR m8/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=LfSaGWms; 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 n8-v6si11634855wrb.79.2018.05.02.19.04.56; Wed, 02 May 2018 19:04:57 -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=LfSaGWms; 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 9036268A503; Thu, 3 May 2018 05:04:21 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f180.google.com (mail-wr0-f180.google.com [209.85.128.180]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1136668A4A1 for ; Thu, 3 May 2018 05:04:15 +0300 (EEST) Received: by mail-wr0-f180.google.com with SMTP id q3-v6so15875887wrj.6 for ; Wed, 02 May 2018 19:04:48 -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=nxXAIBQZIEuRWxK2mr38URA7sNWtkMJ/buVWA2kU4k8=; b=LfSaGWmsJk1qCttooXLim+nIp11qeOQUd3UDAua7w6ks5bgUP/HcaWqFuLM3oJib+x nEPfiXis79FpJB7Fr0vsxoLTaPv+QDW+b00aAaFikz/IKjLkjljRjXsLVpdxC4sMhXZ1 qkcTNh/T8LZYOsWEgRMakG1Vumwt+V4cT2TlrRQCLfUfheGxmWIiaTtr1fktjopcFlJB AIw1ptSlZx/NQEFiI35+iUSJhCsoBWDqbtriPq2xnVvm7NH0iNXBLjkNniAnRopfDTZJ +/0kg0s/uJ7yFYVqKAGgvEkiiWpTFMEt9Vgs3ICkDFux/SLzdQM2UxNl300SbiDtU4nU /qxA== 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=nxXAIBQZIEuRWxK2mr38URA7sNWtkMJ/buVWA2kU4k8=; b=VMtL3+vxmH66QJIH+1P7aQxtV456iBDw3RQn5QBkgQ3vBTMz+F7S9oURxxe/CXEfE/ hyTJWzeiSJNE+3dttAm4U37njxsCJae/pYGPruKca3YF5mpc3v7T1Jx1XaMma8zopJj2 ZuaXqSLKeQpIQWFTyGZP6QYdc9KmgdfacFIeV8CSMBB2b8VjgGl+LADMlGTHlLPsSJvf CySa1F4YOh8fFlfhpU8gBKn0JCZznrOAO5NIxYegRv5PZY7F9/4MCebH0sBoaWYywvWs 4G1NHL1iUMMZ+qVCt62qUNQPztOTc9eMx7kM6O6iHYgOvHIkIorKpNCsiAfJFpQXV7sq XObw== X-Gm-Message-State: ALQs6tBBMOyE+fEod0E1I9izI5OrPMudgQkXnSQTV7S9jQ/xzwcucqDP 8sclae66LWW1uef+95uOJb1mXA== X-Received: by 2002:adf:9607:: with SMTP id b7-v6mr15528042wra.129.1525313087515; Wed, 02 May 2018 19:04:47 -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 k3-v6sm22114086wri.28.2018.05.02.19.04.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 May 2018 19:04:46 -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: <6934cdec-227e-da50-3f03-7401da7a6a5e@gmail.com> Date: Thu, 3 May 2018 04:04:38 +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: [FFmpeg-devel] [PATCH v3]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. > 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. > > 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. > Hi version 2 missed one occurence of:  nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE) (two checks are needed at two different places along with nvenc_check_capabilities(avctx) ). Sorry for the double posting. Thanks From 20790a867b3c799300622176b506c8ed384961c6 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..d0598d379e 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -457,6 +457,8 @@ static av_cold int nvenc_check_device(AVCodecContext *avctx, int idx) if ((ret = nvenc_check_capabilities(avctx)) < 0) goto fail3; + ctx->dynamic_bitrate = nvenc_check_cap(avctx, NV_ENC_CAPS_SUPPORT_DYN_BITRATE_CHANGE); + av_log(avctx, loglevel, "supports NVENC\n"); dl_fn->nvenc_device_count++; @@ -550,6 +552,8 @@ 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); + } 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);