From patchwork Tue Jun 30 01:54:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 20741 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 9F1CB44946F for ; Tue, 30 Jun 2020 05:23:35 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 77BAC680A1D; Tue, 30 Jun 2020 05:23:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f194.google.com (mail-il1-f194.google.com [209.85.166.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92ED9680722 for ; Tue, 30 Jun 2020 05:23:28 +0300 (EEST) Received: by mail-il1-f194.google.com with SMTP id k6so16309289ili.6 for ; Mon, 29 Jun 2020 19:23:28 -0700 (PDT) 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=T3IrQ10uFs1cvKtUJ7FbRlMYX1YRcoCGNpxqN/McJ8M=; b=tHz0y0PfC0596phjbQklYX8aAdbsBtNwzBPEctpXImIilaZ6Ed+N8aXVvjheSebrEO 2hMORTa0aatbKdy7oeIuyHpxLLMc8CxgFFcgfzoe+WYJ45ItHuSmcFjy4PaOpx7vXF3Q jzaNfelx7u2CPFe0GXoKVcyhxMkEHtEjMN2m3uQo3hmFjrksuwSIvQTbS4Za8fA8+Nwi t+scYo4xpWeXvbia3mcnXCzpiVPnzsOsrMyTAYQVTXtbvbiCAbsJuLlH2H8vN4KL+9/Y nSY33NGhFWsu6LCMDcybde6Potq2TYGhay3eNchKxS2NWTiwRCEsijJ/IHaxDCuLqu6c mO8A== 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=T3IrQ10uFs1cvKtUJ7FbRlMYX1YRcoCGNpxqN/McJ8M=; b=JNjyvvmipT2T7Frbqye/qKWzxuk5S3VNfdMDTKo+zk2n20wt9h1Qe3f6thQxQ7z0PZ 6gUWe5PuD0E/3n6MoV8Q2N8c3asrdFMp/HtfHB2lZKplKcxbKhyKnB3Plawv8mpXC3tk 0fNLN9rqJIbguVsi99ojjbs+W8wgohbBpYH5G0g518eQY+z3F5lME0EYP59Y4k/8iKKV lnC4dRkPa5pG5B/BDqm0uoq55vbgMXHEbGAlUgJIoagyTfWRsz/lIHF1m3BKgeYyEoNN +pXGVlgyD2nU/Cp5CuO59/iECbDBYx5GXcBvFW9o+yc9FBrFaA2dtXNXpkHLcrHC87AS MOjQ== X-Gm-Message-State: AOAM531GmNrPqPLcueBcjJRwQl2UB1h82cjRJGXY406v1cIRQ3fMvdok NEz9JV+TNuIWX2gskeBPNQG0LNEK2Gc= X-Google-Smtp-Source: ABdhPJwccMCFU1Vq6Tp3p7uInjSbZfZzM71Kl/GyoXVr6HUJNO7+JKvdO6FcVOVwfyXnbXVTjTuqdQ== X-Received: by 2002:a63:f316:: with SMTP id l22mr12389068pgh.291.1593482074183; Mon, 29 Jun 2020 18:54:34 -0700 (PDT) Received: from wangcao.mtv.corp.google.com ([2620:0:1000:4011:7b84:dc77:c8b2:63c]) by smtp.gmail.com with ESMTPSA id e5sm626167pjv.18.2020.06.29.18.54.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jun 2020 18:54:33 -0700 (PDT) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Jun 2020 18:54:25 -0700 Message-Id: <20200630015425.4047954-1-wangcao@google.com> X-Mailer: git-send-email 2.27.0.212.ge8ba1cc988-goog In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/libaomenc.c: Add super-resolution options to libaom wrapper 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" From: Wang Cao Signed-off-by: Wang Cao --- Check libaom ABI version to use SUPERRES enum in aom_encoder.h doc/encoders.texi | 36 +++++++++++++++++++++++++++++++++ libavcodec/libaomenc.c | 46 ++++++++++++++++++++++++++++++++++++++++++ libavcodec/version.h | 2 +- 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 17a0f4c821..80052763db 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1599,6 +1599,42 @@ Enable the use of global motion for block prediction. Default is true. Enable block copy mode for intra block prediction. This mode is useful for screen content. Default is true. +@item superres-mode (@emph{mode}) +Select super-resolution mode. + +@table @option +@item none (@emph{0}) +No frame superres allowed. + +@item fixed (@emph{1}) +All frames are coded at the specified scale and super-resolved. + +@item random (@emph{2}) +All frames are coded at a random scale and super-resolved. + +@item qthresh (@emph{3}) +Superres scale for a frame is determined based on q_index. + +@item auto (@emph{4}) +Automatically select superres for appropriate frames. +@end table + +@item superres_denominator +The denominator for superres to use when @option{superres-mode} is @option{fixed}. +Valid value ranges from 8 to 16. + +@item superres_kf_denominator +The denominator for superres to use on key frames when +@option{superres-mode} is @option{fixed}. Valid value ranges from 8 to 16. + +@item superres_qthresh +The q level threshold after which superres is used when @option{superres-mode} +is @option{qthresh}. Valid value ranges from 1 to 63. + +@item superres_kf_qthresh +The q level threshold after which superres is used for key frames when +@option{superres-mode} is @option{qthresh}. Valid value ranges from 1 to 63. + @end table @section libkvazaar diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index fe98449fa1..4959f84c2c 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -23,6 +23,7 @@ * AV1 encoder support via libaom */ +#include #define AOM_DISABLE_CTRL_TYPECHECKS 1 #include #include @@ -96,6 +97,11 @@ typedef struct AOMEncoderContext { int enable_restoration; int usage; int tune; + int superres_mode; + int superres_denominator; + int superres_qthresh; + int superres_kf_denominator; + int superres_kf_qthresh; } AOMContext; static const char *const ctlidstr[] = { @@ -135,6 +141,7 @@ static const char *const ctlidstr[] = { #endif [AV1E_SET_ENABLE_CDEF] = "AV1E_SET_ENABLE_CDEF", [AOME_SET_TUNING] = "AOME_SET_TUNING", + [AV1E_SET_ENABLE_SUPERRES] = "AV1E_SET_ENABLE_SUPERRES", }; static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc) @@ -204,6 +211,13 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx, width, "tile_width_count:", cfg->tile_width_count, width, "tile_height_count:", cfg->tile_height_count); av_log(avctx, level, "\n"); + av_log(avctx, level, "super resolution settings\n" + " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n ", + width, "rc_superres_mode:", cfg->rc_superres_mode, + width, "rc_superres_denominator:", cfg->rc_superres_denominator, + width, "rc_superres_qthresh:", cfg->rc_superres_qthresh, + width, "rc_superres_kf_denominator:", cfg->rc_superres_kf_denominator, + width, "rc_superres_kf_qthresh:", cfg->rc_superres_kf_qthresh); } static void coded_frame_add(void *list, struct FrameListData *cx_frame) @@ -546,6 +560,17 @@ static av_cold int aom_init(AVCodecContext *avctx, return AVERROR(EINVAL); } + if (ctx->superres_mode >= 0) + enccfg.rc_superres_mode = ctx->superres_mode; + if (ctx->superres_qthresh > 0) + enccfg.rc_superres_qthresh = ctx->superres_qthresh; + if (ctx->superres_kf_qthresh > 0) + enccfg.rc_superres_kf_qthresh = ctx->superres_kf_qthresh; + if (ctx->superres_denominator >= 8) + enccfg.rc_superres_denominator = ctx->superres_denominator; + if (ctx->superres_kf_denominator >= 8) + enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator; + dump_enc_cfg(avctx, &enccfg); enccfg.g_w = avctx->width; @@ -688,6 +713,8 @@ static av_cold int aom_init(AVCodecContext *avctx, // codec control failures are currently treated only as warnings av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n"); codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used); + if (ctx->superres_mode > 0) + codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, 1); if (ctx->auto_alt_ref >= 0) codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref); if (ctx->arnr_max_frames >= 0) @@ -1107,6 +1134,25 @@ static const AVOption options[] = { { "tune", "The metric that the encoder tunes for. Automatically chosen by the encoder by default", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_TUNE_SSIM, VE, "tune"}, { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_PSNR}, 0, 0, VE, "tune"}, { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = AOM_TUNE_SSIM}, 0, 0, VE, "tune"}, +#if AOM_ENCODER_ABI_VERSION >= 22 + { "superres-mode", "Select super-resultion mode", OFFSET(superres_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, AOM_SUPERRES_AUTO, VE, "superres_mode"}, + { "none", "No frame superres allowed", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_NONE}, 0, 0, VE, "superres_mode"}, + { "fixed", "All frames are coded at the specified scale and super-resolved", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_FIXED}, 0, 0, VE, "superres_mode"}, + { "random", "All frames are coded at a random scale and super-resolved.", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_RANDOM}, 0, 0, VE, "superres_mode"}, + { "qthresh", "Superres scale for a frame is determined based on q_index", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_QTHRESH}, 0, 0, VE, "superres_mode"}, + { "auto", "Automatically select superres for appropriate frames", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_SUPERRES_AUTO}, 0, 0, VE, "superres_mode"}, +#else + { "superres-mode", "Select super-resultion mode", OFFSET(superres_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 4, VE, "superres_mode"}, + { "none", "No frame superres allowed", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "superres_mode"}, + { "fixed", "All frames are coded at the specified scale and super-resolved", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "superres_mode"}, + { "random", "All frames are coded at a random scale and super-resolved.", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "superres_mode"}, + { "qthresh", "Superres scale for a frame is determined based on q_index", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "superres_mode"}, + { "auto", "Automatically select superres for appropriate frames", 0, AV_OPT_TYPE_CONST, {.i64 = 4}, 0, 0, VE, "superres_mode"}, +#endif + { "superres-denominator", "The denominator for superres to use, range [8, 16]", OFFSET(superres_denominator), AV_OPT_TYPE_INT, {.i64 = 8}, 8, 16, VE}, + { "superres-qthresh", "The q level threshold after which superres is used, range [1, 63]", OFFSET(superres_qthresh), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE}, + { "superres-kf-denominator", "The denominator for superres to use on key frames, range [8, 16]", OFFSET(superres_kf_denominator), AV_OPT_TYPE_INT, {.i64 = 8}, 8, 16, VE}, + { "superres-kf-qthresh", "The q level threshold after which superres is used for key frames, range [1, 63]", OFFSET(superres_kf_qthresh), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE}, FF_AV1_PROFILE_OPTS { NULL }, }; diff --git a/libavcodec/version.h b/libavcodec/version.h index 03593026b3..05f59901ff 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -29,7 +29,7 @@ #define LIBAVCODEC_VERSION_MAJOR 58 #define LIBAVCODEC_VERSION_MINOR 93 -#define LIBAVCODEC_VERSION_MICRO 100 +#define LIBAVCODEC_VERSION_MICRO 101 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \