From patchwork Sat Mar 9 01:21:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam John X-Patchwork-Id: 12267 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 A0F5B4478BF for ; Sat, 9 Mar 2019 03:22:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7A412680A95; Sat, 9 Mar 2019 03:22:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B43C1680653 for ; Sat, 9 Mar 2019 03:21:55 +0200 (EET) Received: by mail-qk1-f202.google.com with SMTP id o2so17543710qkb.11 for ; Fri, 08 Mar 2019 17:21:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=rtZMbD+dkyScji0UMSHQMmiGTVbDLa6FUi07xW5qkmo=; b=m0teQCbCviq8LEvZejl4bPnKSDMzKRcRiY+akss2Ooz4X3DzH05WTjrYDViCJR/lEs Az7ox5Llpka9QqXrAXyegOPzzZH/2xVajukXvtlZeJrEo29pD/mq2VaoH/k3Wo9IcTIf xHoxRsbIZmxtxrcaqUpQkXTLAI8zd5KF6RtHlEcKftOOWVnUMMIWyaeLIW0LcoEHU0RE RNrS6FLFW9QSCGEvTO2P3MN+18OcGWx0E5zYwHPNXHPGU4yFyTiycAAeYOBWf1dZwVfR +3wQBZWFwgf5opGYLJL3QUL4fkCFp+9HjnT3R3Lvt/73Ee1YnsUvRfXlLuOHXIc12xrN CsUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=rtZMbD+dkyScji0UMSHQMmiGTVbDLa6FUi07xW5qkmo=; b=ghYSRqr5/W4aMyJLJibA8neQAYmZGt/SRuOZ93PkYcpkUbjjSwiMX7c31rg8AB/kQu HnbnhlTuWF629aTy5Xr7i/+nqbpna8H6JX/3eZrBP2xkUwmpjtjVbTz7HlahjzDjTVAt RgkWRP/5NWfryjqZhqiWC97t38jVMjuEODN/kkBHEP7CLbjcbvCMcCNlK6MGEkUjk/6n NyNveTzHHK0IspVr2yS26vH9usOT+N4Pr6LQ/C+A9eXfBmH6uMwFz0HfQnGjEvE7228B 1yteRdi39tQFZIEIkhu8EJLCRVkiTOLBgxFcDP7QYo5lvg2tEo/9dt/pgx4BrWlJsrR9 qLJw== X-Gm-Message-State: APjAAAXHeygny4gEj2f+BDxemnZb0GTJg3ogNpTMSSO8T0r1p8gI5yA+ 1NqTJKo30bc8aKvBRxGW9eWHKx+T2H6c19oVdVr9tVS9Hr2ioSPh+beyvQu4lwP/urRSJqIlwwB ryvVa7CtFVTSC5wTP0/wCI76vJlWT5MKpJP0VKGAJioXGavoRiqS/YZFBzdwF02925A== X-Google-Smtp-Source: APXvYqwIIH05a9O68LwohDJli6gz0eD3of0XUZKopkvAZdFK5Gp315Fsn/HNJWCjkGZAEiv9GQ6XwwETy4tJ X-Received: by 2002:ae9:f70f:: with SMTP id s15mr6690519qkg.4.1552094513943; Fri, 08 Mar 2019 17:21:53 -0800 (PST) Date: Fri, 8 Mar 2019 17:21:47 -0800 In-Reply-To: <7556c8a7-3774-90aa-433f-6fa5cc71806f@gmail.com> Message-Id: <20190309012147.222305-1-samjohn@google.com> Mime-Version: 1.0 References: <7556c8a7-3774-90aa-433f-6fa5cc71806f@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog From: Sam John To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] Added more commandline options for libaom encoder. 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: Sam John Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The following are the newly added options: arnr_max_frames, arnr_strength, aq_mode, denoise_noise_level, denoise_block_size, rc_undershoot_pct, rc_overshoot_pct, minsection_pct, maxsection_pct, frame_parallel, enable_cdef, and enable_global_motion. Also added macros for compiling for aom 1.0.0. --- libavcodec/libaomenc.c | 86 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index faec61cacd..8e0ba7241e 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -66,36 +66,65 @@ typedef struct AOMEncoderContext { struct FrameListData *coded_frame_list; int cpu_used; int auto_alt_ref; + int arnr_max_frames; + int arnr_strength; + int aq_mode; int lag_in_frames; int error_resilient; int crf; int static_thresh; int drop_threshold; + int denoise_noise_level; + int denoise_block_size; uint64_t sse[4]; int have_sse; /**< true if we have pending sse[] */ uint64_t frame_number; + int rc_undershoot_pct; + int rc_overshoot_pct; + int minsection_pct; + int maxsection_pct; + int frame_parallel; int tile_cols, tile_rows; int tile_cols_log2, tile_rows_log2; aom_superblock_size_t superblock_size; int uniform_tiles; int row_mt; + int enable_cdef; + int enable_global_motion; } AOMContext; static const char *const ctlidstr[] = { [AOME_SET_CPUUSED] = "AOME_SET_CPUUSED", [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL", [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF", + [AOME_SET_ARNR_MAXFRAMES] = "AOME_SET_ARNR_MAXFRAMES", + [AOME_SET_ARNR_STRENGTH] = "AOME_SET_ARNR_STRENGTH", [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD", [AV1E_SET_COLOR_RANGE] = "AV1E_SET_COLOR_RANGE", [AV1E_SET_COLOR_PRIMARIES] = "AV1E_SET_COLOR_PRIMARIES", [AV1E_SET_MATRIX_COEFFICIENTS] = "AV1E_SET_MATRIX_COEFFICIENTS", [AV1E_SET_TRANSFER_CHARACTERISTICS] = "AV1E_SET_TRANSFER_CHARACTERISTICS", + [AV1E_SET_AQ_MODE] = "AV1E_SET_AQ_MODE", + [AV1E_SET_FRAME_PARALLEL_DECODING] = "AV1E_SET_FRAME_PARALLEL_DECODING", [AV1E_SET_SUPERBLOCK_SIZE] = "AV1E_SET_SUPERBLOCK_SIZE", [AV1E_SET_TILE_COLUMNS] = "AV1E_SET_TILE_COLUMNS", [AV1E_SET_TILE_ROWS] = "AV1E_SET_TILE_ROWS", #ifdef AOM_CTRL_AV1E_SET_ROW_MT [AV1E_SET_ROW_MT] = "AV1E_SET_ROW_MT", #endif +#ifdef AV1E_SET_DENOISE_NOISE_LEVEL + [AV1E_SET_DENOISE_NOISE_LEVEL] = "AV1E_SET_DENOISE_NOISE_LEVEL", +#endif +#ifdef AV1E_SET_DENOISE_BLOCK_SIZE + [AV1E_SET_DENOISE_BLOCK_SIZE] = "AV1E_SET_DENOISE_BLOCK_SIZE", +#endif +#ifdef AV1E_SET_MAX_REFERENCE_FRAMES + [AV1E_SET_MAX_REFERENCE_FRAMES] = "AV1E_SET_MAX_REFERENCE_FRAMES", +#endif +#ifdef AV1E_SET_ENABLE_GLOBAL_MOTION + [AV1E_SET_ENABLE_GLOBAL_MOTION] = "AV1E_SET_ENABLE_GLOBAL_MOTION", +#endif + [AV1E_SET_ENABLE_CDEF] = "AV1E_SET_ENABLE_CDEF", }; static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc) @@ -567,10 +596,14 @@ static av_cold int aom_init(AVCodecContext *avctx, // 0-100 (0 => CBR, 100 => VBR) enccfg.rc_2pass_vbr_bias_pct = round(avctx->qcompress * 100); - if (avctx->bit_rate) + if (ctx->minsection_pct >= 0) + enccfg.rc_2pass_vbr_minsection_pct = ctx->minsection_pct; + else if (avctx->bit_rate) enccfg.rc_2pass_vbr_minsection_pct = avctx->rc_min_rate * 100LL / avctx->bit_rate; - if (avctx->rc_max_rate) + if (ctx->maxsection_pct >= 0) + enccfg.rc_2pass_vbr_maxsection_pct = ctx->maxsection_pct; + else if (avctx->rc_max_rate) enccfg.rc_2pass_vbr_maxsection_pct = avctx->rc_max_rate * 100LL / avctx->bit_rate; @@ -582,6 +615,11 @@ static av_cold int aom_init(AVCodecContext *avctx, avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate; enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6; + if (ctx->rc_undershoot_pct >= 0) + enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct; + if (ctx->rc_overshoot_pct >= 0) + enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct; + // _enc_init() will balk if kf_min_dist differs from max w/AOM_KF_AUTO if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size) enccfg.kf_min_dist = avctx->keyint_min; @@ -643,7 +681,12 @@ static av_cold int aom_init(AVCodecContext *avctx, codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used); if (ctx->auto_alt_ref >= 0) codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref); - + if (ctx->arnr_max_frames >= 0) + codecctl_int(avctx, AOME_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames); + if (ctx->arnr_strength >= 0) + codecctl_int(avctx, AOME_SET_ARNR_STRENGTH, ctx->arnr_strength); + if (ctx->enable_cdef >= 0) + codecctl_int(avctx, AV1E_SET_ENABLE_CDEF, ctx->enable_cdef); codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh); if (ctx->crf >= 0) codecctl_int(avctx, AOME_SET_CQ_LEVEL, ctx->crf); @@ -651,6 +694,10 @@ static av_cold int aom_init(AVCodecContext *avctx, codecctl_int(avctx, AV1E_SET_COLOR_PRIMARIES, avctx->color_primaries); codecctl_int(avctx, AV1E_SET_MATRIX_COEFFICIENTS, avctx->colorspace); codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, avctx->color_trc); + if (ctx->aq_mode >= 0) + codecctl_int(avctx, AV1E_SET_AQ_MODE, ctx->aq_mode); + if (ctx->frame_parallel >= 0) + codecctl_int(avctx, AV1E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel); set_color_range(avctx); codecctl_int(avctx, AV1E_SET_SUPERBLOCK_SIZE, ctx->superblock_size); @@ -659,6 +706,23 @@ static av_cold int aom_init(AVCodecContext *avctx, codecctl_int(avctx, AV1E_SET_TILE_ROWS, ctx->tile_rows_log2); } +#ifdef AV1E_SET_DENOISE_NOISE_LEVEL + if (ctx->denoise_noise_level >= 0) + codecctl_int(avctx, AV1E_SET_DENOISE_NOISE_LEVEL, ctx->denoise_noise_level); +#endif +#ifdef AV1E_SET_DENOISE_BLOCK_SIZE + if (ctx->denoise_block_size >= 0) + codecctl_int(avctx, AV1E_SET_DENOISE_BLOCK_SIZE, ctx->denoise_block_size); +#endif +#ifdef AV1E_SET_ENABLE_GLOBAL_MOTION + if (ctx->enable_global_motion >= 0) + codecctl_int(avctx, AV1E_SET_ENABLE_GLOBAL_MOTION, ctx->enable_global_motion); +#endif +#ifdef AV1E_SET_MAX_REFERENCE_FRAMES + if (avctx->refs >= 0) { + codecctl_int(avctx, AV1E_SET_MAX_REFERENCE_FRAMES, avctx->refs); + } +#endif #ifdef AOM_CTRL_AV1E_SET_ROW_MT codecctl_int(avctx, AV1E_SET_ROW_MT, ctx->row_mt); #endif @@ -988,15 +1052,31 @@ static const AVOption options[] = { "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE}, { "lag-in-frames", "Number of frames to look ahead at for " "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, + { "arnr-max-frames", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, + { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE}, + { "aq-mode", "adaptive quantization mode", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4, VE, "aq_mode"}, + { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "aq_mode" }, + { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode" }, + { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode" }, + { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode" }, { "error-resilience", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"}, { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"}, { "crf", "Select the quality for constant quality mode", offsetof(AOMContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, { "static-thresh", "A change threshold on blocks below which they will be skipped by the encoder", OFFSET(static_thresh), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, { "drop-threshold", "Frame drop threshold", offsetof(AOMContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE }, + { "denoise-noise-level", "Amount of noise to be removed", OFFSET(denoise_noise_level), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, INT_MAX, VE}, + { "denoise-block-size", "Denoise block size ", OFFSET(denoise_block_size), AV_OPT_TYPE_INT, {.i64 = 32 }, 0, INT_MAX, VE}, + { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, + { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, + { "minsection-pct", "GOP min bitrate (% of target)", OFFSET(minsection_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, + { "maxsection-pct", "GOP max bitrate (% of target)", OFFSET(maxsection_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 5000, VE }, + { "frame-parallel", "Enable frame parallel decodability features", OFFSET(frame_parallel), AV_OPT_TYPE_BOOL,{.i64 = -1}, -1, 1, VE}, { "tiles", "Tile columns x rows", OFFSET(tile_cols), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, VE }, { "tile-columns", "Log2 of number of tile columns to use", OFFSET(tile_cols_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE}, { "tile-rows", "Log2 of number of tile rows to use", OFFSET(tile_rows_log2), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE}, { "row-mt", "Enable row based multi-threading", OFFSET(row_mt), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VE}, + { "enable-cdef", "Enable CDEF filtering", OFFSET(enable_cdef), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VE}, + { "enable-global-motion", "Enable global motion", OFFSET(enable_global_motion), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, VE}, { NULL } };