From patchwork Sat Sep 14 06:28:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lynne X-Patchwork-Id: 51577 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:9fc3:0:b0:48e:c0f8:d0de with SMTP id k3csp213092vqy; Fri, 13 Sep 2024 23:29:09 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUVDFteObWaDxhn/P8lSyz16jMU/jOVBEdUrHVBjr8Kz7vefs+yByHb7wmy482H1ZadG83Rm9tZ570PVq466h3v@gmail.com X-Google-Smtp-Source: AGHT+IFK0+y3XA9M3ZuXYS8mOJhRqDS1bawQdvhF4WqBM6Slz4A5/Ru5UcrCADSQRsfrgHtOqDdC X-Received: by 2002:a17:907:97c8:b0:a90:17fc:3f60 with SMTP id a640c23a62f3a-a902949aeacmr373610866b.8.1726295349411; Fri, 13 Sep 2024 23:29:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726295349; cv=none; d=google.com; s=arc-20240605; b=KxbIrhkJw1Eg1BZZZnbc5rAGlcgWnl6e1Wuy49F98gOxMTahZqqEPtrU60UtG7u2Ce Ku9NZHpH4X4SEUpFQD9rLxEb4ekL9fOiE5soyFY15oaECtLXnPCFu2CZvmMS2w0MzT9G zQLswYrcTV9xR31K6t+uFBuo7Rx3jdmNicKW985kZj8w+NWCfeDMN/rAAaLAXhyjWbXZ zouWt+Lz+fezuAnzhpWNxDrCQq1VZVLh7FX/7khLkikZSwwg54KjGIsW5RD+Ae/jfNfO PqMbEijWhC08G91MhzhKfhjTf/Rpvr4lIim/Am2jvEddgsdynxu0PEQiAN5AbDg28EpR kKWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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:mime-version:message-id:date:to :delivered-to; bh=5TBKt6l4tDRjKQjGOk1Z/GMTE3txPSM6QkJZp1Wf7JY=; fh=nenT92/WZoU6unXd3J6UhGUdod4piddKfVtctNBOh6k=; b=PuKaiYn44bFP3lhpzM7NldzpTI7LvgdJuAG+GbWRH4WGyVMABprtSzGeX2sprzIq1F imyC4aavhubFrSqbpwB/rzLusLIhQXNkt1JW8nDqhHLSPPUaH6xbWu48L4O84c9ek9+f oFqdctmE2wUwXVNBnjhyqGkDnDz64q5nLDzMoCAhfDK0rJd+jbMM5eJYKQTXvBkaCaK9 /rKVGzZned+P57nlsLncrt/sVY/GLIfYyKSFkDrnG6EoRvZg7aDjt7XYm8fpJJ2LDLZL mQ/6atmg/glRB1+KjYuwu1BEl/GgVYAAn0k3zooWHjX06f0gmZtIdw4nzsNm+UYlJpPv hVbQ==; dara=google.com 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 a640c23a62f3a-a90612ef6a0si55957166b.662.2024.09.13.23.29.08; Fri, 13 Sep 2024 23:29:09 -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; 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 74B2E68DD9F; Sat, 14 Sep 2024 09:29:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vidala.lynne.ee (vidala.pars.ee [116.203.72.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 12BBB68DCAE for ; Sat, 14 Sep 2024 09:28:58 +0300 (EEST) To: ffmpeg-devel@ffmpeg.org Date: Sat, 14 Sep 2024 08:28:50 +0200 Message-ID: <20240914062856.132625-1-dev@lynne.ee> X-Mailer: git-send-email 2.45.2.753.g447d99e1c3b MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] hw_base_enc: inject side data to crop output for AV1 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: Lynne via ffmpeg-devel From: Lynne Reply-To: FFmpeg development discussions and patches Cc: Lynne Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: H5bwjPGYogc8 Unlike H264/H265, AV1 contains no fields to crop encoded output to specific sizes. AMD's hardware cannot handle encoding of unaligned dimensions for AV1, hence it codes 1920x1080 as 1920x1088. Add side data to crop the output back to the original dimensions. There's an AV1-spec extension planned to fix this here: https://github.com/AOMediaCodec/av1-spec/pull/346 But it seems to have stuck for now. --- libavcodec/hw_base_encode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libavcodec/hw_base_encode.c b/libavcodec/hw_base_encode.c index 7b6ec97d3b..6e67c9c301 100644 --- a/libavcodec/hw_base_encode.c +++ b/libavcodec/hw_base_encode.c @@ -22,6 +22,7 @@ #include "libavutil/log.h" #include "libavutil/mem.h" #include "libavutil/pixdesc.h" +#include "libavutil/intreadwrite.h" #include "encode.h" #include "avcodec.h" @@ -551,6 +552,30 @@ int ff_hw_base_encode_set_output_property(FFHWBaseEncodeContext *ctx, (3 * ctx->output_delay + ctx->async_depth)]; } + if ((avctx->codec_id == AV_CODEC_ID_AV1) && + ((avctx->coded_width != avctx->width) || + (avctx->coded_height != avctx->height)) { + int err; + size_t crop_data_size = 4*4; + + uint8_t *crop_data = av_mallocz(crop_data_size); + if (!crop_data) { + av_buffer_unref(&pkt->buf); + return AVERROR(ENOMEM); + } + + AV_WL32(&crop_data[2], ctx->surface_width - avctx->width); + AV_WL32(&crop_data[3], ctx->surface_height - avctx->height); + + err = av_packet_add_side_data(pkt, AV_PKT_DATA_FRAME_CROPPING, + crop_data, crop_data_size); + if (err < 0) { + av_buffer_unref(&pkt->buf); + av_free(crop_data); + return err; + } + } + return 0; }