From patchwork Mon Mar 26 05:51:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengfei Qu X-Patchwork-Id: 8175 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp3159410jad; Sun, 25 Mar 2018 22:51:41 -0700 (PDT) X-Google-Smtp-Source: AG47ELvkWQ3R/sZucnnt/NdoSTJu+Bg+W6WoxI0DyxWAkmOc/8V8+ylHWeeIDasU4hCDHot6ZFhv X-Received: by 10.28.177.86 with SMTP id a83mr13939241wmf.143.1522043501427; Sun, 25 Mar 2018 22:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522043501; cv=none; d=google.com; s=arc-20160816; b=yUpflDh/miIFmrnFMrAo7jSKY9E+/nVZ2TdsWtQ0hD2YbQbllOfGXiqkzOfuMIZa9Z GRB4W8YwnE/STXcYRHr0dVI5spwsq3R29SW5mpKmVhFGe6jS1B6YLnL1WBbjUKvxo06e dtoMPDC56ME/bPI2zYnYbdo2UJJrDaLeAr+n8pbTPSUj4PYkyLJSD3Db8D39TztIKNwr tZ+AJ/5o7MlNwBELn6aIFa1t87kvzMevr4jxGtdc/wEaiS4JV0g66bUjpxK8A7eOEit1 LWBZ8SKCE5lv9bF3ABM0IKY5h2rl2seXFQiPcwj/mU0NLJpduGKl8OwQbr4isCAurRTX N3LQ== 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:delivered-to:arc-authentication-results; bh=a8cOxtj9HxPuieE5DCw8GMlGvxZhPclQj+fa7fmQ9As=; b=N7Xh/lYTQARAgd40SDokk5UcuVVoK7WCT5OGuYtRXNJc/BL7AP2xg2wPOu/2Ohh0HN rvYpooZ4kEfayeZook16N7oyeaT3jWVLKuQQPem2ZDMCkWecr9DaLf2c6ijVnY+jcbku wy9hizvtX5nsCfdkY8zC3dn7H4NJL3x1C5+aCONbZRwbKXhG4K/Gojyz5ePGB/PlUNhl uIneYS7B7VdYIgClELfVPni1fPGAHzWZxVIUtDkNJmPKQKPAB8xvpmvScSqnlQcOzWAj atqVRtiX1SA6EVPvzXMA9wxFAtNt3AJdFWeckhJuHCY//YCv+jRDhLxvo62FtYLbtndW uLOw== ARC-Authentication-Results: i=1; mx.google.com; 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 g202si9327774wmg.129.2018.03.25.22.51.41; Sun, 25 Mar 2018 22:51:41 -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; 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 55FBC680D4E; Mon, 26 Mar 2018 08:51:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C7BB6680570 for ; Mon, 26 Mar 2018 08:51:05 +0300 (EEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 Mar 2018 22:51:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,363,1517904000"; d="scan'208";a="185976496" Received: from skl-bj-01.bj.intel.com ([10.238.144.117]) by orsmga004.jf.intel.com with ESMTP; 25 Mar 2018 22:51:20 -0700 From: Pengfei Qu To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Mar 2018 13:51:18 +0800 Message-Id: <20180326055118.32367-2-Pengfei.Qu@intel.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20180326055118.32367-1-Pengfei.Qu@intel.com> References: <20180326055118.32367-1-Pengfei.Qu@intel.com> Subject: [FFmpeg-devel] [V2 2/2] lavc/vaapi_encode: fix to set the default max bitrate for VBR 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: Pengfei Qu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The current RC(CBR/VBR) mode in ffmpeg-vaapi depends on the target bitrate and max bitrate. CBR when target bitrate equal to max bitrate, or VBR. Here is the background to have this solution. One issue I saw when doing transcoding Mpeg2(interlace)->AVC on VBR mode, the real output bitrate go away too much compared to target bitrate when there is no max bitrate parameter in the command line. It work well when set the correct max bitrate parameter in the command line. And for VBR mode in the codec, generally the max bit rate is bigger than the taraget bitrate. For CBR mode, the max bitrate is same as the target bitrate. When there is no specfic setting for the max bit rate parameter in the command, here the default value 95% is used to caculate the default max bitrate accordingly. The original code set max bitrate same as the target bitrate with the rc_target_percentage=100. The value "95" is also the experienced value and here give an initial max bitrate closer to the target bitrate and avoid bigger fluctuation. Signed-off-by: Pengfei Qu --- libavcodec/vaapi_encode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 78347d4..47110cf 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -1164,8 +1164,8 @@ static av_cold int vaapi_encode_init_rate_control(AVCodecContext *avctx) } else { if (avctx->rc_max_rate < avctx->bit_rate) { // Max rate is unset or invalid, just use the normal bitrate. - rc_bits_per_second = avctx->bit_rate; - rc_target_percentage = 100; + rc_target_percentage = 95; + rc_bits_per_second = (unsigned long)(avctx->bit_rate * 100.0 / rc_target_percentage); } else { rc_bits_per_second = avctx->rc_max_rate; rc_target_percentage = (unsigned long)(avctx->bit_rate * 100) / rc_bits_per_second;