[FFmpeg-cvslog] avcodec/ac3enc: Avoid needlessly copying encoded packets around

Andreas Rheinhardt git at videolan.org
Fri Apr 2 14:01:32 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Mar 29 18:54:46 2021 +0200| [5d4234b3ea376c59a53a9ab6fb69aae8c5ee8fac] | committer: Andreas Rheinhardt

avcodec/ac3enc: Avoid needlessly copying encoded packets around

AC-3 and EAC-3 are codecs whose packet sizes are known in advance,
so one can use the min_size parameter of ff_alloc_packet2() to
allocate exactly this amount. This avoids a memcpy later in
av_packet_make_refcounted() in encode_simple_internal().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=5d4234b3ea376c59a53a9ab6fb69aae8c5ee8fac
---

 libavcodec/ac3enc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 4cfd0afe12..fc4d45651d 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1759,7 +1759,8 @@ int ff_ac3_encode_frame_common_end(AVCodecContext *avctx, AVPacket *avpkt,
 
     ac3_quantize_mantissas(s);
 
-    if ((ret = ff_alloc_packet2(avctx, avpkt, s->frame_size, 0)) < 0)
+    ret = ff_alloc_packet2(avctx, avpkt, s->frame_size, s->frame_size);
+    if (ret < 0)
         return ret;
     ac3_output_frame(s, avpkt->data);
 



More information about the ffmpeg-cvslog mailing list