From patchwork Fri Feb 7 18:36:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wonkap Jang X-Patchwork-Id: 17714 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 A1081446D99 for ; Fri, 7 Feb 2020 20:37:02 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8329668B0B1; Fri, 7 Feb 2020 20:37:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 81B2C68B07B for ; Fri, 7 Feb 2020 20:36:56 +0200 (EET) Received: by mail-pf1-f202.google.com with SMTP id w14so229324pfc.19 for ; Fri, 07 Feb 2020 10:36:56 -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; bh=5AU1AQaJnYwon5pX0dxj5+/T3jL/LT4gurrbdlRkA7M=; b=VBOVlhqYdYHw4Pxkx2xSMW8bCinv0D7UcvvBWqnsqmTRr/djnIQvEgAzhzhBiEkuJ9 Q6rNem6AV6jdxZ65aLuZjhTzyZimZYqeWwRzgUBVVYFQNohcr+upbf2Xv0BE8mYWWxLV 2H999Qj+08e4JAImBf2UYjuqqWxkZRzDQxS0XnIqTtjmLiC8c4TCIPIKBkXGguEGcEZ7 gl0QgJhDbY8W3tG4MZDs9fDdK2t2Q0eQFQh0hU4NRtgZ0sTcZHc8RKPv3AA3GLKeDvT3 CN08fuf4LbW/v5O9jcoBotC6xXHYVNHuppj+vBBdA6BTZZr+56cuaf+VuH5AXUA9cIAU 4W0Q== 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; bh=5AU1AQaJnYwon5pX0dxj5+/T3jL/LT4gurrbdlRkA7M=; b=e63TEG7ABoUocfD2zLaK7WtXULrsvE2p1hzdlxA/ZaYNs4a3ludy1YZx56PWvtoKGx 6Yq0Hg/ghmSiN2aWK4eG9gAgjEMDOYUMiGnXOebkWCIVphR9pppb4GAyNlC2qpBkGgfz S5Dt4aS1Hp/AvC4iTY3ysOb93JM2zNSKYktuhRWzWfJQL0A2+cTh+UU4A3RUblIPyP9z 8ueC1yQyiHeQUkveRMbFyA76l96Iu6no2YA9q4l6/F+nNsnfkBxEhLnV00zaJUI5OuAG 93fqrKWLrbwgA2OA11QqKGoemHqguGiyjYMLgW4sAo77yl+cEquJiyPunw8PPsWvvHsq 9grA== X-Gm-Message-State: APjAAAX+AKPXDUOotZFVqASzbaPExvUkEdu9IndvOQrkc3apMKZxxDyW xZ6iwf9ZBjDrnZnN+fntgwJxKFjWx4VONtJ/tJGfrMFKizAcjh+3FlcxR+HpCebb3sow7+/9/iv l/zBzKXCACE6ycRqcTExX0U69NfaCRoAk4KllME8tv69esxMHM0LF2dunPYc+z6g= X-Google-Smtp-Source: APXvYqwLemNaDdHJl6/5d+sfn+xqTgtUyzcXGe09JK+Qp0DT4++NUmoKkDxtd+X18ggAp1b7/nDiPa4R0X4= X-Received: by 2002:a63:ae0a:: with SMTP id q10mr597446pgf.178.1581100614388; Fri, 07 Feb 2020 10:36:54 -0800 (PST) Date: Fri, 7 Feb 2020 10:36:51 -0800 In-Reply-To: Message-Id: <20200207183651.177513-1-wonkap@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog From: Wonkap Jang To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH v6] avcodec/libvpxenc: add a way to explicitly set temporal layer id 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" In order for rate control to correctly allocate bitrate to each temporal layer, correct temporal layer id has to be set to each frame. This commit provides the ability to set correct temporal layer id for each frame. --- doc/encoders.texi | 8 +++++++- libavcodec/libvpxenc.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/doc/encoders.texi b/doc/encoders.texi index 7bae39435e..b1c4740fe9 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -1918,7 +1918,13 @@ Currently supports the following options. @table @option @item 0 No temporal layering flags are provided internally, -relies on flags being passed in using metadata in AVFrame. +relies on flags being passed in using metadata in AVFrame with following keys. +@table @option +@item vp8-flags +Sets the flags passed into the encoder to indicate the referencing scheme for the current frame. +@item temporal_id +Explicitly sets the temporal id of the current frame to encode. +@end table @item 2 Two temporal layers. 0-1... @item 3 diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c index d522c43928..60a858853d 100644 --- a/libavcodec/libvpxenc.c +++ b/libavcodec/libvpxenc.c @@ -1519,11 +1519,22 @@ static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, #endif if (frame->pict_type == AV_PICTURE_TYPE_I) flags |= VPX_EFLAG_FORCE_KF; - if (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id == AV_CODEC_ID_VP8 && frame->metadata) { + if (frame->metadata) { AVDictionaryEntry* en = av_dict_get(frame->metadata, "vp8-flags", NULL, 0); if (en) { flags |= strtoul(en->value, NULL, 10); } + + memset(&layer_id, 0, sizeof(layer_id)); + + en = av_dict_get(frame->metadata, "temporal_id", NULL, 0); + if (en) { + layer_id.temporal_layer_id = strtoul(en->value, NULL, 10); +#ifdef VPX_CTRL_VP9E_SET_MAX_INTER_BITRATE_PCT + layer_id.temporal_layer_id_per_spatial[0] = layer_id.temporal_layer_id; +#endif + layer_id_valid = 1; + } } if (sd) {