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 A8069460FC for ; Mon, 5 Jun 2023 10:19:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2A81D68C396; Mon, 5 Jun 2023 13:19:36 +0300 (EEST) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90E1E68C0F7 for ; Mon, 5 Jun 2023 13:19:29 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 52C0B2404EC for ; Mon, 5 Jun 2023 12:19:29 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 300o7pmeEJ4n for ; Mon, 5 Jun 2023 12:19:28 +0200 (CEST) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id A0FFF240177 for ; Mon, 5 Jun 2023 12:19:28 +0200 (CEST) Received: by lain.khirnov.net (Postfix, from userid 1000) id 832F81601B2; Mon, 5 Jun 2023 12:19:28 +0200 (CEST) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: References: Mail-Followup-To: FFmpeg development discussions and patches Date: Mon, 05 Jun 2023 12:19:28 +0200 Message-ID: <168596036850.3843.16759199081478040168@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] avcodec/cuviddec: update amount of decoder surfaces from within sequence decode callback 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Quoting Roman Arzumanyan (2023-06-05 09:30:07) > Hello, > > This patch reduces vRAM usage by cuvid decoder implementation. > The number of surfaces used for decoding is updated within the parser > sequence decode callback. > Also the "surfaces" AVDictionary option specific to cuvid was removed in > favor of "extra_hw_surfaces". This can break existing workflows, you should deprecated the option instead and only remove it after some time has passed. > > vRAM consumption was tested on various videos and savings are between 1% > for 360p resolution up to 21% for some 1080p H.264 videos. > Decoding performance was tested on various H.264 and H.265 videos in > different resolutions from 360p and higher, no performance penalty was > found. > > From 32a1b016e88fa40b983318d4583750ef250a78d9 Mon Sep 17 00:00:00 2001 > From: Roman Arzumanyan > Date: Thu, 1 Jun 2023 11:17:39 +0300 > Subject: [PATCH] libavcodec/cuviddec: determine DPB size from within cuvid > parser > > --- > libavcodec/cuviddec.c | 29 +++++++++++++++++++++++++++-- > 1 file changed, 27 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/cuviddec.c b/libavcodec/cuviddec.c > index 3d43bbd466..759ed49870 100644 > --- a/libavcodec/cuviddec.c > +++ b/libavcodec/cuviddec.c > @@ -115,6 +115,12 @@ typedef struct CuvidParsedFrame > > #define CHECK_CU(x) FF_CUDA_CHECK_DL(avctx, ctx->cudl, x) > > +// NV recommends [2;4] range > +#define CUVID_MAX_DISPLAY_DELAY (4) > + > +// Actual DPB size will be determined by parser. > +#define CUVID_DEFAULT_NUM_SURFACES (CUVID_MAX_DISPLAY_DELAY + 1) > + > static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* format) > { > AVCodecContext *avctx = opaque; > @@ -309,6 +315,25 @@ static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* form > return 0; > } > > + if (ctx->nb_surfaces < format->min_num_decode_surfaces + 3) > + ctx->nb_surfaces = format->min_num_decode_surfaces + 3; FFMAX() > + > + if (avctx->extra_hw_frames > 0) > + ctx->nb_surfaces += avctx->extra_hw_frames; > + > + if (0 > av_fifo_realloc2(ctx->frame_queue, ctx->nb_surfaces * sizeof(CuvidParsedFrame))) { this is the old deprecated AVFifoBuffer API, you cannot use it with AVFifo objects you should also forward the actual error code > + av_log(avctx, AV_LOG_ERROR, "Failed to recreate frame queue on video sequence callback\n"); > + ctx->internal_error = AVERROR(EINVAL); > + return 0; > + } > + > + ctx->key_frame = av_realloc_array(ctx->key_frame, ctx->nb_surfaces, sizeof(int)); > + if (!ctx->key_frame) { > + av_log(avctx, AV_LOG_ERROR, "Failed to recreate key frame queue on video sequence callback\n"); > + ctx->internal_error = AVERROR(EINVAL); Leaks key_frame on failure and should be ENOMEM. -- Anton Khirnov _______________________________________________ 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".