From patchwork Sun Nov 27 00:46:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Miroslav_Sluge=C5=88?= X-Patchwork-Id: 1571 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.90.1 with SMTP id o1csp1103954vsb; Sat, 26 Nov 2016 16:46:18 -0800 (PST) X-Received: by 10.28.13.9 with SMTP id 9mr12613176wmn.50.1480207578781; Sat, 26 Nov 2016 16:46:18 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ec14si48941201wjb.87.2016.11.26.16.46.17; Sat, 26 Nov 2016 16:46:18 -0800 (PST) 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=@email.cz; dkim=neutral (body hash did not verify) header.i=@email.cz; 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 dis=NONE) header.from=email.cz Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4C3A6689B73; Sun, 27 Nov 2016 02:46:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mxs1.seznam.cz (mxs1.seznam.cz [77.75.78.125]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 71CD3689A33 for ; Sun, 27 Nov 2016 02:46:03 +0200 (EET) Received: from email.seznam.cz by email-smtpc1b.ko.seznam.cz (email-smtpc1b.ko.seznam.cz [10.53.13.15]) id 3e403b310a97232d3ed2123c; Sun, 27 Nov 2016 01:46:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1480207567; bh=m+B0VPQ4JbFoBA6fBusDAfDUatFcveD2PJBp2U/i4vE=; h=DKIM-Signature:Received:From:Subject:To:Message-ID:Date: User-Agent:MIME-Version:Content-Type; b=TxorPUWbfjJ7rgCaa/QlKNjiBmNvHybl09116SLKgkGxHAgklkQjUw+fblEYIIwOt wHiuBId7r9Gi8LpSIZ7m59VXn3vR760mKxIVbSg3+Prxz3NpaSLrYmOdB58cyCINoT HwIAvbBHnQiVTZjxoVFbhsrgZ22h8oH/JbP5tgmY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=email.cz; s=beta; t=1480207567; bh=m+B0VPQ4JbFoBA6fBusDAfDUatFcveD2PJBp2U/i4vE=; h=Received:From:Subject:To:Message-ID:Date:User-Agent:MIME-Version: Content-Type; b=ecfDK1PFu2Pl5a9UePDqgwyiiGTpiOoTuMmvjkiUGq4KSS6vFPXXpU0zo+woCK4TO kGU7j7eGb3ErZRFwO++JPS1qbFDWm5mKZwrUO8+2vyIQuuy0Rgb1dvSh+7mecRwULh 1ckz6WSVtHSdSAPdUpLnM26ijHZAwXYzmfrmx7+E= Received: from [192.168.0.6] (ip-94-113-140-7.net.upcbroadband.cz [94.113.140.7]) by email-relay20.ko.seznam.cz (Seznam SMTPD 1.3.41) with ESMTP; Sun, 27 Nov 2016 01:46:07 +0100 (CET) From: =?UTF-8?Q?Miroslav_Sluge=c5=88?= To: ffmpeg-devel@ffmpeg.org Message-ID: <583A2CCE.5050507@email.cz> Date: Sun, 27 Nov 2016 01:46:06 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] nvenc: always reduce DAR width and height 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" This patch will fix/change: 1. avctx->sample_aspect_ratio.num == 1 and avctx->sample_aspect_ratio.den != 1: There is bug in old comparison, so with this aspect ratio for example 1/2 old alghoritm will produce aspect ratio 1/1 2. Old algorithm also does compute with negative numbers, which should not be used 3. Always reducing DAR width and height is very useful for future use when we will be monitoring aspect ratio change for reseting encoder... From 53bda222d1a3d4c461816d144dcecf792762da49 Mon Sep 17 00:00:00 2001 From: Miroslav Slugen Date: Sun, 27 Nov 2016 01:34:30 +0100 Subject: [PATCH 1/1] nvenc: always reduce DAR width and height --- libavcodec/nvenc.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/libavcodec/nvenc.c b/libavcodec/nvenc.c index d24d278..58dcc5c 100644 --- a/libavcodec/nvenc.c +++ b/libavcodec/nvenc.c @@ -940,18 +940,15 @@ static av_cold int nvenc_setup_encoder(AVCodecContext *avctx) ctx->encode_config.version = NV_ENC_CONFIG_VER; - if (avctx->sample_aspect_ratio.num && avctx->sample_aspect_ratio.den && - (avctx->sample_aspect_ratio.num != 1 || avctx->sample_aspect_ratio.num != 1)) { - av_reduce(&dw, &dh, - avctx->width * avctx->sample_aspect_ratio.num, - avctx->height * avctx->sample_aspect_ratio.den, - 1024 * 1024); - ctx->init_encode_params.darHeight = dh; - ctx->init_encode_params.darWidth = dw; - } else { - ctx->init_encode_params.darHeight = avctx->height; - ctx->init_encode_params.darWidth = avctx->width; - } + dw = avctx->width; + dh = avctx->height; + if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0) { + dw*= avctx->sample_aspect_ratio.num; + dh*= avctx->sample_aspect_ratio.den; + } + av_reduce(&dw, &dh, dw, dh, 1024 * 1024); + 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; -- 2.1.4