From patchwork Thu May 14 18:15:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zachariah Brown X-Patchwork-Id: 19689 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2D798449867 for ; Thu, 14 May 2020 21:15:54 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 02C1E688170; Thu, 14 May 2020 21:15:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from p3plsmtpa12-09.prod.phx3.secureserver.net (p3plsmtpa12-09.prod.phx3.secureserver.net [68.178.252.238]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B9BE4687F40 for ; Thu, 14 May 2020 21:15:46 +0300 (EEST) Received: from localhost.localdomain ([68.72.140.10]) by :SMTPAUTH: with ESMTPA id ZIOVjCcXnNPMpZIOWjgzKY; Thu, 14 May 2020 11:15:44 -0700 X-CMAE-Analysis: v=2.3 cv=SoHuF8G0 c=1 sm=1 tr=0 a=wIrylLPe0GKJj1pZ/DtEuw==:117 a=wIrylLPe0GKJj1pZ/DtEuw==:17 a=9YtzbQ2jAAAA:8 a=1sf3vzKa6MQPWSWrUJwA:9 a=3k35bvVMLvsPF10q:21 a=O9tn_fdsiYKjFGFT:21 a=x5PCt48jHDcr_qrlleZq:22 X-SECURESERVER-ACCT: zachariah@renewedvision.com From: Zachariah Brown To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 May 2020 14:15:33 -0400 Message-Id: <20200514181533.2010-1-zachariah@renewedvision.com> X-Mailer: git-send-email 2.23.0.windows.1 MIME-Version: 1.0 X-CMAE-Envelope: MS4wfBomKSg14I7dvof9I7jWiPSvHWU3Q2EVVRr/UcnJSYJQhoGpNCZflZLg7v1deDnRLVoRgogPD1FyVNA0zH5q3MKFeXjLL3EOUnh/gJgBf6mqRsTzgvOi 3r8dsXvhQyCjwzGK46RA5Vyw/xH0c0rR6bypxmuTWZUzYMihtUF/4iK4T2zpbziUqQ+98H5Gkbjjv/QXWI4Xg5wtAoQCJem4OAelL4aEuWCrkx0Ex+N4ZuOG Subject: [FFmpeg-devel] [PATCH] avcodec/nvenc: Update the encoder to use the framerate (if available) in the codec context 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: Zachariah Brown Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The h264_nvenc and hevc_nvenc encoders aren't respecting the framerate in the codec context. Instead it was using the timebase which in our use-case was 1/1000 so the encoder was behaving as if we wanted 1000fps. This resulted in poor encoding results due to an extremely low bitrate. Both the amf and qsv encoders already contain similar logic to first check the framerate before falling back to the timebase. Signed-off-by: Zachariah Brown --- libavcodec/nvenc.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index 068d469ae6..cbdddd33f9 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -1209,8 +1209,13 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx) ctx->init_encode_params.darHeight = dh; ctx->init_encode_params.darWidth = dw; - ctx->init_encode_params.frameRateNum = avctx->time_base.den; - ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame; + if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { + ctx->init_encode_params.frameRateNum = avctx->framerate.num; + ctx->init_encode_params.frameRateDen = avctx->framerate.den; + } else { + ctx->init_encode_params.frameRateNum = avctx->time_base.den; + ctx->init_encode_params.frameRateDen = avctx->time_base.num * avctx->ticks_per_frame; + } ctx->init_encode_params.enableEncodeAsync = 0; ctx->init_encode_params.enablePTD = 1;