From patchwork Mon Dec 30 19:20:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 17072 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 36D9B448545 for ; Mon, 30 Dec 2019 21:21:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DE3F768AC26; Mon, 30 Dec 2019 21:21:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9B1B068A9B5 for ; Mon, 30 Dec 2019 21:20:59 +0200 (EET) Received: by mail-pl1-f179.google.com with SMTP id f20so14990421plj.5 for ; Mon, 30 Dec 2019 11:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=D1Lk9GKbQGWXWSp16rIoOf6ABV3pqs3GWDRZVDUZWaY=; b=A8NH8KKHRcPbjuS5D9m7YJF1f+VahYoYdaZuMkcnKDLwEZbeyJwCRhyMKAxS/ZXHb8 kxiObmgnmmBQPBrvha3kcOQVRWk9G0gwHpJWPwvVB0YJwGZJQbNIw6WwKO2b9aFFrjTY L6Qlzm78FA2kpk6W0bZa4uskAYDPa9gLjTHiJT5z0300ytG9x4VV52cN9Dv+UwNmOP52 uyJjseR+VZEknLCFORtMYT70IbnrX/DL4cBDtC885tJuEQzG29VIjSOqrs2hMX2KAPpP 6k+V+A8/ahK/hPv1SbzUQ+MBj+z9DDey4Xm03B+9taF8mDYNp++81RMhfcCoM3v7bych aOYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=D1Lk9GKbQGWXWSp16rIoOf6ABV3pqs3GWDRZVDUZWaY=; b=XpDThAKVqLFztjHMwBTM4t6yyPY5AMvuJbNrAH7379qcBRdp3kil1YHiGK9COJ2jBA uKpo/3r00BWeKj/kHCn6RH1jY/tMmQ8+BgRzNt31liaXf10S3P1493aSOKgy+7Ght29Z 46wKrheIi2Fv/T4g0p3RJ6sXDIxp1KqiwzAgUCk0lbUgNHdLpkX9VpxvVOAo85psusPh F59HF4UIEQDzNTOUJcGyURGUe4TXdrrQ+1xjr2ChoO+upsgnQgUn0sBEQBFcw9sIwY3Q yFfHS65uUnE16d6Ir8aQN9HfRaA/RzpBC5Slsza8dHjpAGP133TCPsEnm953GiZQd+Jl Wb6w== X-Gm-Message-State: APjAAAXgp6oJ6Z/0b3ZnA4RazfQ7aBzuMKiwjXLu/46HvT4AgWW5CNJt XRD0JLCPKYi8vkqlApMLzftoxuGm X-Google-Smtp-Source: APXvYqzpOYeDDwX38NsudHLsFZ6B+kD3hmN2Hs0Fh10mOWsunq+vpXcHmEKvWV3/WXsSqLTpNxOPZQ== X-Received: by 2002:a17:902:694c:: with SMTP id k12mr57976727plt.329.1577733657210; Mon, 30 Dec 2019 11:20:57 -0800 (PST) Received: from localhost.localdomain ([181.23.77.192]) by smtp.gmail.com with ESMTPSA id p17sm51275102pfn.31.2019.12.30.11.20.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Dec 2019 11:20:56 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Mon, 30 Dec 2019 16:20:06 -0300 Message-Id: <20191230192009.2462-1-jamrial@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4 v2] avcodec/libx265: apply some global AVCodecContext settings to the encoder 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" There's no reason to ignore them if set. Signed-off-by: James Almer --- doc/encoders.texi | 14 ++++++++++++++ libavcodec/libx265.c | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index a207363650..673eaf6496 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -2415,6 +2415,20 @@ during configuration. You need to explicitly configure the build with @subsection Options @table @option +@item b +Sets target video bitrate. + +@item bf + +@item g +Set the GOP size. + +@item keyint_min +Minimum GOP size. + +@item refs +Number of reference frames each P-frame can use. The range is from @var{1-16}. + @item preset Set the x265 preset. diff --git a/libavcodec/libx265.c b/libavcodec/libx265.c index 963c28fb1d..798ba12efa 100644 --- a/libavcodec/libx265.c +++ b/libavcodec/libx265.c @@ -82,10 +82,26 @@ static av_cold int libx265_encode_close(AVCodecContext *avctx) return 0; } +static av_cold int libx265_param_parse_int(AVCodecContext *avctx, + const char *key, int value) +{ + libx265Context *ctx = avctx->priv_data; + char buf[256]; + + snprintf(buf, sizeof(buf), "%d", value); + if (ctx->api->param_parse(ctx->params, key, buf) == X265_PARAM_BAD_VALUE) { + av_log(avctx, AV_LOG_ERROR, "Invalid value %d for param \"%s\".\n", value, key); + return AVERROR(EINVAL); + } + + return 0; +} + static av_cold int libx265_encode_init(AVCodecContext *avctx) { libx265Context *ctx = avctx->priv_data; AVCPBProperties *cpb_props = NULL; + int ret; ctx->api = x265_api_get(av_pix_fmt_desc_get(avctx->pix_fmt)->comp[0].depth); if (!ctx->api) @@ -241,6 +257,27 @@ static av_cold int libx265_encode_init(AVCodecContext *avctx) if (!(avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER)) ctx->params->bRepeatHeaders = 1; + if (avctx->gop_size >= 0) { + ret = libx265_param_parse_int(avctx, "keyint", avctx->gop_size); + if (ret < 0) + return ret; + } + if (avctx->keyint_min > 0) { + ret = libx265_param_parse_int(avctx, "min-keyint", avctx->keyint_min); + if (ret < 0) + return ret; + } + if (avctx->max_b_frames >= 0) { + ret = libx265_param_parse_int(avctx, "bframes", avctx->max_b_frames); + if (ret < 0) + return ret; + } + if (avctx->refs >= 0) { + ret = libx265_param_parse_int(avctx, "ref", avctx->refs); + if (ret < 0) + return ret; + } + if (ctx->x265_opts) { AVDictionary *dict = NULL; AVDictionaryEntry *en = NULL; @@ -556,6 +593,10 @@ static const AVClass class = { static const AVCodecDefault x265_defaults[] = { { "b", "0" }, + { "bf", "-1" }, + { "g", "-1" }, + { "keyint_min", "-1" }, + { "refs", "-1" }, { NULL }, };