From patchwork Tue Mar 3 21:43:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Cao X-Patchwork-Id: 18020 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 67E7C44BA0E for ; Tue, 3 Mar 2020 23:43:44 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 53F7B68B5FD; Tue, 3 Mar 2020 23:43:44 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pl1-f193.google.com (mail-pl1-f193.google.com [209.85.214.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F2E668B60C for ; Tue, 3 Mar 2020 23:43:38 +0200 (EET) Received: by mail-pl1-f193.google.com with SMTP id y8so26466pll.13 for ; Tue, 03 Mar 2020 13:43:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xS2eufp12/JpuhcR8WkBTx+pomalR4GdbFYjWCaIu88=; b=WzYA71gygfLEUf47CCmdZBIq64FDNn8OMhwC1NCaEPCkosGOn32s9UllBqRR+2d1jk Esvl3IvEoPbeAXgAXVfKGm86gXcJDFIrEdbioI+t4GWK0GBFWoye6QNBrSVhtRbbYEjV DYviB9kEUepqUxUhavv8D2JUUO1peb0AulxGcgVem4UOd2aawMUxNA/DwxhlxJlina7D IDj/4TXBvnc8AZ5WqCHy01v7iPpsfJCA2cV8XYRo4wp9f83eyUKJVXIxX39z9W4L8zNK Txe28LLgeHDnQgUaUyXPc928pj6WUENn8JH0DINgUwxpsJPvfRy691coE/XFMDC6XgTR Dzdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xS2eufp12/JpuhcR8WkBTx+pomalR4GdbFYjWCaIu88=; b=LKJRKh795IqK1xpTB/8r6Sw5ttxPC8qPt4hWA/Yz3qbLmpXDlrLELoqvYQnEwooCKW EA4ktc9MqKFd6flMnSggrMYha7HOUynT5jjwQf6bsyyljOGyi1y703uaIoXpcXRsyNWd kIPVbQNMHWZuLuH+lYgjKTdyrKgB3ELYHD6LOdSqzZPZgBYpUjKnl5e6VTO5sM/jbTPr o5pTJgerssgS+qcJgws8QW8kiqpG9tvxC0mvGjye2G7o1fCgz6YnrtPn3u4/NrpEoHSr S2tNnr52OERFrmIhbpkV0kC7KiF2Agv1PvW6zoOO3BPU+rIPxB5qHONX47SjitQT2YPC ktWA== X-Gm-Message-State: ANhLgQ3lZ6/x7nrEr+wJy9O8zl7WEsSmqogS3TAmEyeFihQUOSQ5ozha 1QLQ+WrBpeAL//WAex7yvopvb0MV9Pkh7Q== X-Google-Smtp-Source: ADFU+vthXxoql/HsrJenyYbjkz1mOHPNr1DZ1Hm1sd6HyHyq4zDkX7MfD9tFvTPDJ0ZIKS/1LyH/kw== X-Received: by 2002:a17:90a:328f:: with SMTP id l15mr92755pjb.55.1583271816048; Tue, 03 Mar 2020 13:43:36 -0800 (PST) Received: from wangcao.bej.corp.google.com ([2401:fa00:45:201:7885:4f90:fa40:35]) by smtp.gmail.com with ESMTPSA id q8sm169763pje.2.2020.03.03.13.43.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 13:43:35 -0800 (PST) From: Wang Cao X-Google-Original-From: Wang Cao To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Mar 2020 05:43:21 +0800 Message-Id: <20200303214321.39335-2-wangcao@google.com> X-Mailer: git-send-email 2.25.0.265.gbab2e86ba0-goog In-Reply-To: <20200303214321.39335-1-wangcao@google.com> References: <20200303214321.39335-1-wangcao@google.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] libavcodec/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 Cc: Wang Cao , Wang Cao Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Wang Cao Signed-off-by: Wang Cao --- doc/encoders.texi | 39 +++++++++++++++++++++++++++++++++++++++ libavcodec/libaomenc.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index 4215f237bd..ac00c305d5 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1608,6 +1608,45 @@ 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 enable-superres (@emph{boolean}) +Enable super-resolution during the encoding process. + +@item superres-mode (@emph{mode}) +Select super-resultion 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 is fixed 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 7fd624c470..f1578db5e6 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -95,6 +95,12 @@ typedef struct AOMEncoderContext { int enable_restoration; int usage; int tune; + int enable_superres; + int superres_mode; + int superres_denominator; + int superres_qthresh; + int superres_kf_denominator; + int superres_kf_qthresh; } AOMContext; static const char *const ctlidstr[] = { @@ -134,6 +140,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) @@ -203,6 +210,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) @@ -545,6 +559,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 >= 0) + enccfg.rc_superres_denominator = ctx->superres_denominator; + if (ctx->superres_kf_denominator >= 0) + enccfg.rc_superres_kf_denominator = ctx->superres_kf_denominator; + dump_enc_cfg(avctx, &enccfg); enccfg.g_w = avctx->width; @@ -687,6 +712,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->enable_superres >= 0) + codecctl_int(avctx, AV1E_SET_ENABLE_SUPERRES, ctx->enable_superres); if (ctx->auto_alt_ref >= 0) codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref); if (ctx->arnr_max_frames >= 0) @@ -1103,6 +1130,17 @@ static const AVOption options[] = { { "tune", "The metric that encoder tunes for", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE, "tune"}, { "psnr", "PSNR as distortion metric", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune"}, { "ssim", "SSIM as distortion metric", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune"}, + { "enable-superres", "Enable super-resolution mode", OFFSET(enable_superres), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE}, + { "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"}, + { "superres-denominator", "The denominator for superres to use.", OFFSET(superres_denominator), AV_OPT_TYPE_INT, {.i64 = 8}, 8, 16, VE}, + { "superres-qthresh", "The q level threshold after which superres is used", OFFSET(superres_qthresh), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE}, + { "superres-kf-denominator", "The denominator for superres to use on key frames.", 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.", OFFSET(superres_kf_qthresh), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE}, { NULL }, };