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 4926145483 for ; Thu, 25 Jul 2024 13:24:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A647368D648; Thu, 25 Jul 2024 16:24:53 +0300 (EEST) Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 52A1F68D63B for ; Thu, 25 Jul 2024 16:24:46 +0300 (EEST) Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-704494efa7cso463887a34.3 for ; Thu, 25 Jul 2024 06:24:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721913884; x=1722518684; 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=suFQ24G/fxw8cz1mBi52QXxagsIrSuNdczUmcwx8jqw=; b=Ey81VUnAPYwv6uHMLadjJ3W1uZr+EYhJhmBA+zqhZ6avXR6jg/zw+TqGaYRryVKSLT HxX7EYJBnpobXjVc1S3bkqK+yGvZlH+js+MG9SFoE/uazCXjWjeOKSjPlX3FKuSuoHcq V/C1P5mb8pZYM33HadqJZUT3dTuDzlBoShMtKev/3smil6tXFPB/TfJ7HHPUMP/WoslO Rls8m/9IitFd/clIRzB4uPxOPAMSbAmCpFQz7C1DZK0pCXEtmnLQeoNmFDQBgOwniLs0 AJ6Bk8gt1kbmECot2R5vdXLg0hosunBD3SW22Pq9z2MZJTvw6rg4iYkOtp+hylYPTYko Sy/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721913884; x=1722518684; 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=suFQ24G/fxw8cz1mBi52QXxagsIrSuNdczUmcwx8jqw=; b=FTAQvVZ3x2GwFTQaYPNvguofAtmUu7sqIgacLACPG77Xt3FiJ0Cmh41StuLOQt0jTP WP3cgoMka0ssyn7AScu54uKt3LXKPVvwtnWKsAtDtM0WH3UNxTDtGKI06h3cZmduP7Ed fkrfMDH7TAmShqvdfoGSqbLS6yIo7JR37t5UgBFFwBOb3ORbv9xtnLcM6nZLRu1cnns3 4WorDg3KDXG1xdw8st8iZqC/2oRmy1vRVy+hIMKN4sljPffPsy1mxbTmrEPgAsqdvS+w WPPWCXPedwDF+94PvoxaGj+kWKl9zIUFiVdaycHxRPOYjugnm3eHHUDlvqRQiBHWTGGU L+3w== X-Gm-Message-State: AOJu0YyYsje2KpCik6S51Snkg6WTKGCHz6TJrHHbpxKJcWpts0uGdwD2 ILw/Ugd5EvnTdaYinhv+jiqpfKzPs6tvYb+ZHNhBF+6Gs43wsCDlwPHK5A== X-Google-Smtp-Source: AGHT+IH5A8zsmdH826vjcTwHUPNJU4c6GQiLxE24ji+w6Qhtulosiv0UEkS2k/2346VpjgV+VreWJQ== X-Received: by 2002:a05:6830:61c6:b0:703:783a:dad5 with SMTP id 46e09a7af769-709324c628bmr2289706a34.27.1721913883767; Thu, 25 Jul 2024 06:24:43 -0700 (PDT) Received: from [192.168.0.12] ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7a9f836ace5sm1183524a12.34.2024.07.25.06.24.42 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Jul 2024 06:24:43 -0700 (PDT) Message-ID: <793aeef9-478c-4fcd-a879-3f02430775d2@gmail.com> Date: Thu, 25 Jul 2024 10:25:18 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: <20240725120616.785-1-Primeadvice@gmail.com> Content-Language: en-US From: James Almer In-Reply-To: <20240725120616.785-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/25/2024 9:06 AM, Araz Iusubov wrote: > --- > libavcodec/amfenc.c | 6 ++++ > libavcodec/amfenc.h | 3 ++ > libavcodec/amfenc_av1.c | 64 ++++++++++++++++++++++++++++++++++++++++- > 3 files changed, 72 insertions(+), 1 deletion(-) > > diff --git a/libavcodec/amfenc.c b/libavcodec/amfenc.c > index 061859f85c..93925854e0 100644 > --- a/libavcodec/amfenc.c > +++ b/libavcodec/amfenc.c > @@ -402,6 +402,12 @@ int av_cold ff_amf_encode_close(AVCodecContext *avctx) > dlclose(ctx->library); > ctx->library = NULL; > } > + > + if (ctx->crop) > + { > + av_freep(ctx->crop); > + } > + > ctx->trace = NULL; > ctx->debug = NULL; > ctx->factory = NULL; > diff --git a/libavcodec/amfenc.h b/libavcodec/amfenc.h > index 2dbd378ef8..abcf465063 100644 > --- a/libavcodec/amfenc.h > +++ b/libavcodec/amfenc.h > @@ -81,6 +81,9 @@ typedef struct AmfContext { > > int log_to_dbg; > > + //handle crop > + uint32_t *crop; > + > // Static options, have to be set before Init() call > int usage; > int profile; > diff --git a/libavcodec/amfenc_av1.c b/libavcodec/amfenc_av1.c > index d40c71cb33..e9bc26a770 100644 > --- a/libavcodec/amfenc_av1.c > +++ b/libavcodec/amfenc_av1.c > @@ -19,9 +19,13 @@ > #include "libavutil/internal.h" > #include "libavutil/mem.h" > #include "libavutil/opt.h" > +#include "libavutil/intreadwrite.h" > #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 +171,12 @@ 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_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,59 @@ 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) > + // assume older driver and Navi3x > + width_alignment_factor = 64; > + else > + 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) { > + ctx->crop = av_mallocz(sizeof(uint32_t) * 4); > + if (!ctx->crop) { > + av_log(ctx, AV_LOG_WARNING, "Can't allocate memory for amf av1 encoder crop information\n"); > + return AVERROR(ENOMEM); > + } > + > + 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"); > + av_freep(ctx->crop); > + return AVERROR(ENOMEM); > + } > + > + avctx->coded_side_data = sd_crop; > + avctx->nb_coded_side_data++; > + > + //top, bottom, left,right > + AV_WL32(ctx->crop + 0, 0); > + AV_WL32(ctx->crop + 1, crop_bottom); > + AV_WL32(ctx->crop + 2, 0); > + AV_WL32(ctx->crop + 3, crop_right); > + > + 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].data = (uint8_t*)ctx->crop; You're passing ownership of this buffer to the packet side data array yet still try to free it in ff_amf_encode_close() because you kept the pointer around in the encoder's context. In any case, I've fixed this and pushed the patch. Thanks. > + 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".