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 0E66E406CE for ; Wed, 23 Mar 2022 15:58:41 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2066768B1C1; Wed, 23 Mar 2022 17:57:48 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8FD9E68B192 for ; Wed, 23 Mar 2022 17:57:41 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id D8B39240506 for ; Wed, 23 Mar 2022 16:57:37 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id iaCuxDPTfDGJ for ; Wed, 23 Mar 2022 16:57:36 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (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 "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 96C5124017C for ; Wed, 23 Mar 2022 16:57:34 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id 921183A0189; Wed, 23 Mar 2022 16:57:34 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Mar 2022 16:57:14 +0100 Message-Id: <20220323155720.20017-2-anton@khirnov.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220323155720.20017-1-anton@khirnov.net> References: <20220323155720.20017-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/8] lavc/avcodec: only allocate the encoding frame for encoders 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: And only when needed, i.e. for encoders using the simple API. --- libavcodec/avcodec.c | 4 +--- libavcodec/encode.c | 7 +++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index dbaa9f78a2..c7daa385e7 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -180,14 +180,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code avci->buffer_frame = av_frame_alloc(); avci->buffer_pkt = av_packet_alloc(); - avci->es.in_frame = av_frame_alloc(); avci->in_pkt = av_packet_alloc(); avci->last_pkt_props = av_packet_alloc(); avci->pkt_props = av_fifo_alloc2(1, sizeof(*avci->last_pkt_props), AV_FIFO_FLAG_AUTO_GROW); if (!avci->buffer_frame || !avci->buffer_pkt || - !avci->es.in_frame || !avci->in_pkt || - !avci->last_pkt_props || !avci->pkt_props) { + !avci->in_pkt || !avci->last_pkt_props || !avci->pkt_props) { ret = AVERROR(ENOMEM); goto free_and_end; } diff --git a/libavcodec/encode.c b/libavcodec/encode.c index 70bd8da81f..837ffaa40d 100644 --- a/libavcodec/encode.c +++ b/libavcodec/encode.c @@ -412,6 +412,7 @@ int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket * int ff_encode_preinit(AVCodecContext *avctx) { + AVCodecInternal *avci = avctx->internal; int i; if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) { @@ -563,5 +564,11 @@ FF_ENABLE_DEPRECATION_WARNINGS if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) avctx->internal->intra_only_flag = AV_PKT_FLAG_KEY; + if (ffcodec(avctx->codec)->encode2) { + avci->es.in_frame = av_frame_alloc(); + if (!avci->es.in_frame) + return AVERROR(ENOMEM); + } + return 0; } -- 2.34.1 _______________________________________________ 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".