From patchwork Thu Jan 25 17:12:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Dariusz Marcinkiewicz X-Patchwork-Id: 45835 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8888:b0:199:de12:6fa6 with SMTP id d8csp218262pzf; Thu, 25 Jan 2024 09:14:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEO1l9hYSAAbW5pNgDVrcc4zduqSMToI+PnOp1riTKOnGV1EywILiKPO8ee7st5cuBSXVpT X-Received: by 2002:a17:906:d0d8:b0:a2e:8ce7:98be with SMTP id bq24-20020a170906d0d800b00a2e8ce798bemr1396228ejb.2.1706202858835; Thu, 25 Jan 2024 09:14:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706202858; cv=none; d=google.com; s=arc-20160816; b=s8S157d0ZUxQz/X6/QQ9sqZkoJY1U9jbMONyYqbprPL/uPtiH8quqtob6Jm5khEXYY eZgy6apZCL6mOkaiE5LvNLe88zEfgn21n32NAfOHTZRX7Grsc8wUGw0MbgR05sOmG9IH QS5smcK6/uWSuU1F/zysdEMpzbUpViNrYZgo8yeQF7oQIiLg8ib4T+cSHqBsljKtkHgk xhKqdw+8NcZakg08g9zXDZIfPgNWyF6hQo1tLuTrJer+8FSnNhB3taSzSRfG5s4cscoZ KjLpbyBFJiDjXSj9nLSAy6ikjxk4V0/s3PRurISVWMu6lL4NmwrcwFcxdHD6TVwqsKZl OUeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to:from :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:to:mime-version:message-id:date :delivered-to; bh=HVz0B/1bCVAef0KKGj/M7vL2WwZ67+71hwFvsv0tkOk=; fh=OJ4JnL4P68J6S//Gv0xCkgU+iK0db+41ZQQS8iT3NjQ=; b=MkBVMO9aUY0z1darsHYtnatYLeA/HDI0vNmin1LlNJo2l08giLtamQLVO8fgi67RyK Pvf9xKjAZvHUORdcc6lPxGwD/e0wtfN8jDjEIOAGtvRM1vUAMcJIkO5cP8czQNdgbBKG mNUf39Gib/CbT+Qf2Sq6bPdgQj+s2vi58WqryZLsk85DbpMk1Q61eXB4zDgDjQhsvED1 jL4sOSzLHQUkaCYSylnNSbBiCc57Iq2tVH0lzKmCG6+b1IyOzKKYqZsXG/pKgG26CXun PeW1kjLT5VtDa3S9dcve/7bG32yWaEh/MKwUjlaVhKdkDTbIZKnfhHL/PBTu55IkwHO4 JG1g== 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 b19-20020a170906491300b00a31885d70c0si605610ejq.427.2024.01.25.09.14.15; Thu, 25 Jan 2024 09:14:18 -0800 (PST) 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 63F3768D0E1; Thu, 25 Jan 2024 19:14:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 44B1F68A9A7 for ; Thu, 25 Jan 2024 19:13:59 +0200 (EET) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5fffb2798bfso77513857b3.2 for ; Thu, 25 Jan 2024 09:13:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706202837; x=1706807637; h=content-transfer-encoding:cc:to:from:subject:mime-version :message-id:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pDqeiI9tk4Str4Wxwub5ZLxNfYhAlkszQd9ZeUUxpRs=; b=NeIpXEu7zXVAcGNQiJ0q4d4TbJfEhZo1iG0WMo1+S5W808f+GqKjG/+yygIhr54pLu hBOMpS1e0NVDwmZaukEMZQG5mt21E1V/Gg8Y52u1GNWCxWj4ALdWypD+k5c3R8xcyZ8q HTAkKKf70colhishum0e2UYBdxEoisXhRFIy3gSZIXQNayxt4gUXpAC+tZ7DBUgUBWRY OizIh+VVzTAgvWC5msOOmAgchYLpIjwKVkxRn1HujksG+Yg+cHw39UKRHkrnlSwYdyAu s9x247YMOgijqqiIePVOq3MTDr618+JSRseAqED4DrueKudBh4nPGG6t886s/RVnvCrv mcWg== X-Gm-Message-State: AOJu0YzUcvF0XMRi/RmyyDwgNF3z0aeWJs/hNruWwyjs1i6ROM3FNEt0 Xfj2eeJshQILTHXO9w54XLAsOHXY23jTh2msAPthRW2Vrvb6Q54QFak2QRcQfRgbOCU7Sh+8pmp 1Ppkk4QznUMQsaqtK8tHhrm4G2GGmQmZVXOdSwEnjKuZ7G6WiviL3Px5Ffl4zNhlin5oDwZLMXv ennR/hPIxl3FN0NrHWqm+UQuzRKTE80EqAcw== X-Received: from reksio2.lul.corp.google.com ([2620:0:1043:12:396b:5eae:4a3f:f54e]) (user=darekm job=sendgmr) by 2002:a81:994d:0:b0:5ff:9df0:2a4 with SMTP id q74-20020a81994d000000b005ff9df002a4mr47917ywg.7.1706202835516; Thu, 25 Jan 2024 09:13:55 -0800 (PST) Date: Thu, 25 Jan 2024 18:12:49 +0100 Message-Id: <20240125171248.2366132-2-darekm@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] libavcodec: add tune_content option also for VP8. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Dariusz Marcinkiewicz via ffmpeg-devel From: Dariusz Marcinkiewicz Reply-To: FFmpeg development discussions and patches Cc: Dariusz Marcinkiewicz , sprang@webrtc.org Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: NNP+daqotGNj This exposes VP8E_SET_SCREEN_CONTENT_MODE option from libvpx. Change authored by Erik Språng Signed-off-by: Dariusz Marcinkiewicz --- doc/encoders.texi | 7 +++++-- libavcodec/libvpxenc.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index c9fe6d6143..2a9b38f62a 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -2186,6 +2186,11 @@ Enable error resiliency features. Increase sharpness at the expense of lower PSNR. The valid range is [0, 7]. +@item tune-content +Set content type. +For VP8: default (0), screen (1), screen with aggressive rate control (2). +For VP9: default (0), screen (1), film (2). + @item ts-parameters Sets the temporal scalability configuration using a :-separated list of key=value pairs. For example, to specify temporal scalability parameters @@ -2268,8 +2273,6 @@ colorspaces: @end table @item row-mt @var{boolean} Enable row based multi-threading. -@item tune-content -Set content type: default (0), screen (1), film (2). @item corpus-complexity Corpus VBR mode is a variant of standard VBR where the complexity distribution midpoint is passed in rather than calculated for a specific clip or chunk. diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index 80988a2608..c28cca40a2 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -164,6 +164,7 @@ static const char *const ctlidstr[] = { [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT", [VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS", [VP8E_SET_TEMPORAL_LAYER_ID] = "VP8E_SET_TEMPORAL_LAYER_ID", + [VP8E_SET_SCREEN_CONTENT_MODE] = "VP8E_SET_SCREEN_CONTENT_MODE", #if CONFIG_LIBVPX_VP9_ENCODER [VP9E_SET_LOSSLESS] = "VP9E_SET_LOSSLESS", [VP9E_SET_TILE_COLUMNS] = "VP9E_SET_TILE_COLUMNS", @@ -1249,8 +1250,19 @@ static av_cold int vpx_init(AVCodecContext *avctx, codecctl_int(avctx, VP9E_SET_ROW_MT, ctx->row_mt); #endif #ifdef VPX_CTRL_VP9E_SET_TUNE_CONTENT - if (ctx->tune_content >= 0) + if (ctx->tune_content >= 0 && avctx->codec_id == AV_CODEC_ID_VP9) { codecctl_int(avctx, VP9E_SET_TUNE_CONTENT, ctx->tune_content); + } +#endif +#ifdef VPX_CTRL_VP8E_SET_SCREEN_CONTENT_MODE + if (ctx->tune_content >= 0 && avctx->codec_id == AV_CODEC_ID_VP8) { + if (ctx->tune_content == 2 && ctx->is_alpha) { + av_log(avctx, AV_LOG_ERROR, + "Transparency encoding with screen mode with aggressive rate control not supported\n"); + return AVERROR(EINVAL); + } + codecctl_int(avctx, VP8E_SET_SCREEN_CONTENT_MODE, ctx->tune_content); + } #endif #ifdef VPX_CTRL_VP9E_SET_TPL if (ctx->tpl_model >= 0) @@ -1857,6 +1869,21 @@ FF_ENABLE_DEPRECATION_WARNINGS } coded_size = queue_frames(avctx, &ctx->encoder, &ctx->coded_frame_list, pkt); + if (avctx->codec_id == AV_CODEC_ID_VP8 && coded_size == 0 && ctx->tune_content == 2) { + // VP8 tuned for screen content with aggresive rate control - returned + // OK status code but produced no output, this indicates frame was + // rolled back due to bitrate overshoot - try to encode it again. + av_log(avctx, AV_LOG_VERBOSE, + "Attempting to reencode dropped VP8 screencast frame."); + res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp, + avctx->ticks_per_frame, flags, ctx->deadline); + if (res != VPX_CODEC_OK) { + log_encoder_error(avctx, "Error encoding frame"); + return AVERROR_INVALIDDATA; + } + coded_size = queue_frames(avctx, &ctx->encoder, &ctx->coded_frame_list, pkt); + } + if (ctx->is_alpha) { queue_frames(avctx, &ctx->encoder_alpha, &ctx->alpha_coded_frame_list, NULL); @@ -1946,6 +1973,12 @@ static const AVOption vp8_options[] = { { "auto-alt-ref", "Enable use of alternate reference " "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE}, { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, + { "tune-content", "Tune content type", OFFSET(tune_content), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE, "tune_content"}, +#ifdef VPX_CTRL_VP8E_SET_SCREEN_CONTENT_MODE + { "default", "Regular video content", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "tune_content"}, + { "screen", "Screen content mode on", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "tune_content"}, + { "screen-rate-control", "Screen content mode with aggressive rate control", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "tune_content"}, +#endif LEGACY_OPTIONS { NULL } };