From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id BDD134C2AE for ; Tue, 23 Jul 2024 22:06:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C35E068CD8F; Wed, 24 Jul 2024 01:06:05 +0300 (EEST) Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DF1A268CD8F for ; Wed, 24 Jul 2024 01:05:58 +0300 (EEST) Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3daf0e739b2so1895080b6e.0 for ; Tue, 23 Jul 2024 15:05:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721772356; x=1722377156; darn=ffmpeg.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=k82/yE6922hcJj0wZ/WJyJ7qNUgv5akr/Kz80CBdDQU=; b=hVI4ggLbwGXsXW6gDWnzJk9ifhvaEj4vLRpLHJCK7kW1p0Z/O7EB6V3mqKWx40JIhQ 7ZQn9sD63RMxtk/Vr5W65d/4DI5XunyhUDS7l991Ykc71hUEQFnji2OBHbVZUZXy5PaX rlOguPTHewA+Cf0zlun7VOK4NXfLWJkgm+F6/YjbZN0WqlA9CGDAkA/s9zE490oPlhGF A7QcKnFY8aCbQhNBxOPUMWmmKDupgI/zSv+uxjwnGhv2A6r3Ho8R81OSWMVM4o1tYrjV i8DRufObd/CD5gYeXnvNrFvK4HgijCD/G47Hz9/JloLvAa2nc7UJE2FACLyEejp9IQJB XWUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721772356; x=1722377156; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=k82/yE6922hcJj0wZ/WJyJ7qNUgv5akr/Kz80CBdDQU=; b=wWETUxf/+Vj+rF543HTaNQVnUtbOdFeBSL2W9ZkFFaNtdd+xis5PQ8i4+O4Xdjcf1v 8L4nl93VQHWMJZDM5ykVbeFGzbazIIVfa22CAWJwI2Oe8Oj2RetnNEiEo7ejL4WV8MVY Br4/1C7XdwQjhRXHgK899y8DcO30OERIE+FOtExPd78ybYtCnYI94Yt4/hy02rxtVPM8 D/YmR+e0E7BRLF2VVkj5yvCcxqOwDlbp/naqKE/8s0CcJsQDxGVNgv1H4f6ddefOYOru K7Icjv0qNOls1+QLSvS4kvGt7p9rs+jbK2PzZVd60TewTzZPiHjQHo6UjBjmjdqLawjk kHIQ== X-Gm-Message-State: AOJu0YwiyQID2LSsAVXGMZS27bZC3z2FcdpN41hAj4OikBasQUElPMK8 vmlz5Wej65UB2mWuv+lRgoHyNSe5WPZTiKLUw8UXcFAANp2RF4w/OxL9Yw== X-Google-Smtp-Source: AGHT+IH47QZeSvNLsxSNPy767XwxEXAXjwY14Wri05jlDNs0z8GEovcKDcLbalp645kZSaYgqBcLmA== X-Received: by 2002:a05:6808:1528:b0:3d9:2986:5a3b with SMTP id 5614622812f47-3dae63746e6mr14321050b6e.37.1721772356250; Tue, 23 Jul 2024 15:05:56 -0700 (PDT) Received: from [192.168.0.12] ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-79f0f26787dsm6823152a12.76.2024.07.23.15.05.55 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Jul 2024 15:05:55 -0700 (PDT) Message-ID: <34fec9e2-adaa-482a-af86-5ce912712913@gmail.com> Date: Tue, 23 Jul 2024 19:06:27 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: <20240723215356.1737-1-Primeadvice@gmail.com> Content-Language: en-US From: James Almer In-Reply-To: <20240723215356.1737-1-Primeadvice@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH] avcodec/amf_enc: av1 cropping support 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: , Reply-To: FFmpeg development discussions and patches Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 7/23/2024 6:53 PM, Araz Iusubov wrote: > --- > libavcodec/amfenc_av1.c | 82 ++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 81 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c > index d40c71cb33..27599b9fbe 100644 > --- a/libavcodec/amfenc_av1.c > +++ b/libavcodec/amfenc_av1.c > @@ -22,6 +22,9 @@ > #include "amfenc.h" > #include "codec_internal.h" > > +#define AMF_VIDEO_ENCODER_AV1_CAP_WIDTH_ALIGNMENT_FACTOR_LOCAL L"Av1WidthAlignmentFactor" // amf_int64; default = 1 > +#define AMF_VIDEO_ENCODER_AV1_CAP_HEIGHT_ALIGNMENT_FACTOR_LOCAL L"Av1HeightAlignmentFactor" // amf_int64; default = 1 > + > #define OFFSET(x) offsetof(AmfContext, x) > #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM > static const AVOption options[] = { > @@ -167,7 +170,13 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) > AMFRate framerate; > AMFSize framesize = AMFConstructSize(avctx->width, avctx->height); > > - > + //for av1 alignment and crop > + AVPacketSideData* sd_crop = NULL; > + uint32_t* crop = NULL; > + uint32_t crop_right = 0; > + uint32_t crop_bottom = 0; > + int width_alignment_factor = -1; > + int height_alignment_factor = -1; > > if (avctx->framerate.num > 0 && avctx->framerate.den > 0) { > framerate = AMFConstructRate(avctx->framerate.num, avctx->framerate.den); > @@ -482,6 +491,77 @@ FF_ENABLE_DEPRECATION_WARNINGS > buffer->pVtbl->Release(buffer); > var.pInterface->pVtbl->Release(var.pInterface); > > + //processing crop informaiton according to alignment > + if (ctx->encoder->pVtbl->GetProperty(ctx->encoder, AMF_VIDEO_ENCODER_AV1_CAP_WIDTH_ALIGNMENT_FACTOR_LOCAL, &var) != AMF_OK) > + { Don't put the brackets in their own line. > + // assume older driver and Navi3x > + width_alignment_factor = 64; > + } > + else > + { And don't use brackets for a single line block. > + width_alignment_factor = (int)var.int64Value; > + } > + > + if (ctx->encoder->pVtbl->GetProperty(ctx->encoder, AMF_VIDEO_ENCODER_AV1_CAP_HEIGHT_ALIGNMENT_FACTOR_LOCAL, &var) != AMF_OK) > + { > + // assume older driver and Navi3x > + height_alignment_factor = 16; > + } > + else > + { > + height_alignment_factor = (int)var.int64Value; > + } > + > + if (width_alignment_factor != -1 && height_alignment_factor != -1) > + { > + if (avctx->width % width_alignment_factor != 0) > + { > + crop_right = width_alignment_factor - (avctx->width & (width_alignment_factor - 1)); > + } > + > + if (avctx->height % height_alignment_factor != 0) > + { > + crop_bottom = height_alignment_factor - (avctx->height & (height_alignment_factor - 1)); > + } > + > + //There is specia processing for crop_bottom equal to 8 in hardware > + if (crop_bottom == 8) > + { > + crop_bottom = 2; > + } > + } > + > + if (crop_right != 0 || crop_bottom != 0) > + { > + sd_crop = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*sd_crop)); > + if (!sd_crop) > + { > + av_log(ctx, AV_LOG_WARNING, "Can't allocate memory for amf av1 encoder crop information\n"); > + return AVERROR(ENOMEM); > + } > + > + sd_crop->data = (uint8_t*)av_mallocz(sizeof(uint32_t) * 4); This is setting data from the very first side data entry, not the last. You're then setting type and size in the last at the end of this block. > + if (!sd_crop->data) > + { > + av_log(ctx, AV_LOG_WARNING, "Can't allocate memory for amf av1 encoder crop information\n"); > + return AVERROR(ENOMEM); If you return here, avctx->coded_side_data will have a stale pointer. > + } > + > + crop = (uint32_t*)sd_crop->data; > + > + //top, bottom, left,right > + *crop++ = 0; > + *crop++ = crop_bottom; > + *crop++ = 0; > + *crop = crop_right; Just to be safe, use AV_WL32() for these, even if no big endian system supports this encoder. > + > + avctx->nb_coded_side_data++; > + > + avctx->coded_side_data = sd_crop; > + avctx->coded_side_data[avctx->nb_coded_side_data - 1].type = AV_PKT_DATA_FRAME_CROPPING; > + avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = sizeof(uint32_t) * 4; > + } > + > return 0; > } > _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".