From patchwork Sun Sep 9 22:08:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 10283 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp1823832jap; Sun, 9 Sep 2018 15:08:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbR8I/q9m0KjXFwP3MCFjfvuSNE1FjF3zhbJPnF4aKBLIVUfyVKBx26Ty6k5kT1jPpnRL6F X-Received: by 2002:a1c:3351:: with SMTP id z78-v6mr10387750wmz.23.1536530907463; Sun, 09 Sep 2018 15:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536530907; cv=none; d=google.com; s=arc-20160816; b=ASi2CayKCUN6ZtNsS+mFydj4/IFgmBUgZmq9l8nftuqvKarW+h7bqfZTX64kWv5gMT ZhzztndD2lXq7IaaeV/C7koxuqEpAE8DKiX0x07L/NQvkzlakdHj+aKt6SZtcuAoNMkA VudfMltoF57+peeuv9EfeMNDMlMIr0xkGrkimSV5/ypS9uDqx8QZEpiQjZjX2gTt40DA 81zaaXbGcVnRTKKlerbAoVCKhnOsBnORXEmqxDSiSpLCSnAXGFgV8xZibB39cmkht4An uPQ/b4p5QUpcPLLpjm3KGFgOxm4VDgphOw6iHe07U8+NhFfHXAdxXwvUYQz0M0fB7eel Tgug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=mmbsLmxtrhvfKBL1HZM3zbK3xEmSSjtUUJwosTNlnlk=; b=qRafKCI6K5c83fGdmCux0H8mVf1T5o8Ce43iwO1pryxAE9bn+SdIlo0WzJ1t1Svt6F zcz0BhmcY1olyZ0i+va0UL8bmRx/WueKahrvg0RcY67SRfPpgN8mRC5YfxYyBxXeR3IA RK1XSkc3dXjI7Z8hmNDOLOzYlUEpf8RUSIl5RBOAwHlBZIFPIc8cb+fxIo4SYWoqpZUD dlFynK2ZwQTAT2gApKkSNf+xj5Mq/lJSaUpDeHhIUyPVjs4aFTLY4Sqie8h3g9D25gaB Gf/MaNPi+bMVTuENFBPrrVqZtkuvO+CIK7lmPPlvR11KDF6dThsqKiK6zaoQxqkYqr8A bHUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=Pyg3wvcg; 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 u128-v6si11933936wmf.116.2018.09.09.15.08.26; Sun, 09 Sep 2018 15:08:27 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=Pyg3wvcg; 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 ED91D68A296; Mon, 10 Sep 2018 01:08:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0AEF768A0A6 for ; Mon, 10 Sep 2018 01:08:08 +0300 (EEST) Received: by mail-wm0-f49.google.com with SMTP id j25-v6so3911364wmc.1 for ; Sun, 09 Sep 2018 15:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id; bh=5k0Ap1o55PnoSZqKnnhFa+VZSE2SyrQS3nF18aajw7U=; b=Pyg3wvcgYTTAwh7mNZNuKBumj08XOwIqLG0OPV1yE8ZOpm4bCgQWEfC1s2q8kDYLNM yN9k+BTAzGfhX++syD6y46mlSPn7GH7BoDvoqdNe7AD/rOBbke/3bbSJb8wCaWpPwwga QoGRawX28/ryu9o5+il8crINUvgmvL0y/uwWFIuLqjRBg1eB+o9elygHp3Gd5dRALSec IzjPTLHfUcL5mwJX9tQ20QQJOqcpC+xfMT8IOwN1CY2WCq3Aa9+WNRrqJdooF/ZaZ8R/ lIOPNYFeuazTRemGUZAk6ZBDLDI0Y5nTW8+fTLA0hAV6REgrnyRx6b+ampkf4PRniNFk rhUg== 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; bh=5k0Ap1o55PnoSZqKnnhFa+VZSE2SyrQS3nF18aajw7U=; b=HiOJDrtSRAZey5z2rLdWYjZpGEkY78emRltbPf96bXRbFCH2pQ8A8tWb/z74eZGS4W 4BAhfGxCPSZ1cXDgTB34lBAIJgkUKL+ENWyIV63QJEZYYiL+w/X7wh8jjecqon6FArsb fDdzteieTYmFTkhZ0fv2mgUBeB4m11FOVjn7I7eRldsKwcRItO7ON3yJ0KP3EAZgnWnP aOoTZrWAk6hxWNf/isw+bbo3bAhOci0qrVhNRvPQmqzzW9zVKTJvf6AXOFj0Vwo22Twj 3UwIAfk/CORoVDdiYYnET08Ky+7Ow4/yp4UwlbO4VDVrFcRcAia1lo6VH1jLw9Ly9rN5 E5+g== X-Gm-Message-State: APzg51DYQx8u+B7KnvB2DB/XcogvG/PJQMT444GV3gc4QF0NVCk9Ffh4 KjfbTwhlThxCR/cADRDzBuibDQRGZOU= X-Received: by 2002:a1c:cb4d:: with SMTP id b74-v6mr12033078wmg.123.1536530897037; Sun, 09 Sep 2018 15:08:17 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id 75-v6sm29406215wml.21.2018.09.09.15.08.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Sep 2018 15:08:16 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Sun, 9 Sep 2018 23:08:10 +0100 Message-Id: <20180909220812.16171-1-sw@jkqxz.net> X-Mailer: git-send-email 2.18.0 Subject: [FFmpeg-devel] [PATCH 1/3] libaomenc: Add support for tiles 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Adds an option to specify the number of tile rows and columns, then uses equal-sized tiles to fill the frame. --- Useful for testing to make arbitrary arrangements of tiles, though the requirement to set the superblock size for the whole stream at the top level rather than letting it be set dynamically is slightly unfortunate. The rounding error is placed at the left/top here, it might be better to place it around the sides instead? (The most important detail is likely to be in the centre of the frame, so make the tiles there smaller? I'm not sure whether this argument is actually valid, though.) libavcodec/libaomenc.c | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/libavcodec/libaomenc.c b/libavcodec/libaomenc.c index 9431179886..0b4fa71fc7 100644 --- a/libavcodec/libaomenc.c +++ b/libavcodec/libaomenc.c @@ -68,6 +68,7 @@ typedef struct AOMEncoderContext { int static_thresh; int drop_threshold; int noise_sensitivity; + int tile_cols, tile_rows; } AOMContext; static const char *const ctlidstr[] = { @@ -79,6 +80,7 @@ static const char *const ctlidstr[] = { [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_SUPERBLOCK_SIZE] = "AV1E_SET_SUPERBLOCK_SIZE", }; static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc) @@ -143,6 +145,10 @@ static av_cold void dump_enc_cfg(AVCodecContext *avctx, width, "kf_mode:", cfg->kf_mode, width, "kf_min_dist:", cfg->kf_min_dist, width, "kf_max_dist:", cfg->kf_max_dist); + av_log(avctx, level, "tile settings\n" + " %*s%d\n %*s%d\n", + width, "tile_width_count:", cfg->tile_width_count, + width, "tile_height_count:", cfg->tile_height_count); av_log(avctx, level, "\n"); } @@ -294,6 +300,7 @@ static av_cold int aom_init(AVCodecContext *avctx, int res; aom_img_fmt_t img_fmt; aom_codec_caps_t codec_caps = aom_codec_get_caps(iface); + aom_superblock_size_t superblock_size = AOM_SUPERBLOCK_SIZE_DYNAMIC; av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str()); av_log(avctx, AV_LOG_VERBOSE, "%s\n", aom_codec_build_config()); @@ -431,6 +438,51 @@ static av_cold int aom_init(AVCodecContext *avctx, enccfg.g_error_resilient = ctx->error_resilient; + if (ctx->tile_cols && ctx->tile_rows) { + int sb_size, sb_width, sb_height; + int cols_per_tile, cols_step, rows_per_tile, rows_step, i; + + if (avctx->width / ctx->tile_cols < 128 || + avctx->width / ctx->tile_rows < 128) { + // User has requested more tiles than would fit with 128x128 + // superblocks, so assume they want 64x64. + sb_size = 64; + superblock_size = AOM_SUPERBLOCK_SIZE_64X64; + } else { + sb_size = 128; + superblock_size = AOM_SUPERBLOCK_SIZE_128X128; + } + + if (avctx->width / ctx->tile_cols < sb_size || + avctx->height / ctx->tile_rows < sb_size) { + av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: tiles must be " + "at least one superblock wide and high.\n"); + return AVERROR(EINVAL); + } + if (ctx->tile_cols > MAX_TILE_WIDTHS || + ctx->tile_rows > MAX_TILE_HEIGHTS) { + av_log(avctx, AV_LOG_ERROR, "Invalid tile sizing: at most %dx%d " + "tiles allowed.\n", MAX_TILE_WIDTHS, MAX_TILE_HEIGHTS); + return AVERROR(EINVAL); + } + + enccfg.tile_width_count = ctx->tile_cols; + enccfg.tile_height_count = ctx->tile_rows; + + sb_width = (avctx->width + sb_size - 1) / sb_size; + sb_height = (avctx->height + sb_size - 1) / sb_size; + + cols_per_tile = sb_width / ctx->tile_cols; + cols_step = sb_width % ctx->tile_cols; + for (i = 0; i < ctx->tile_cols; i++) + enccfg.tile_widths[i] = cols_per_tile + (i < cols_step); + + rows_per_tile = sb_height / ctx->tile_rows; + rows_step = sb_height % ctx->tile_rows; + for (i = 0; i < ctx->tile_rows; i++) + enccfg.tile_heights[i] = rows_per_tile + (i < rows_step); + } + dump_enc_cfg(avctx, &enccfg); /* Construct Encoder Context */ res = aom_codec_enc_init(&ctx->encoder, iface, &enccfg, flags); @@ -454,6 +506,8 @@ static av_cold int aom_init(AVCodecContext *avctx, codecctl_int(avctx, AV1E_SET_TRANSFER_CHARACTERISTICS, avctx->color_trc); set_color_range(avctx); + codecctl_int(avctx, AV1E_SET_SUPERBLOCK_SIZE, superblock_size); + // provide dummy value to initialize wrapper, values will be updated each _encode() aom_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1, (unsigned char*)1); @@ -746,6 +800,7 @@ static const AVOption options[] = { { "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 }, { "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE}, + { "tiles", "Tile rows x columns", OFFSET(tile_cols), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, VE }, { NULL } };