[FFmpeg-devel] [PATCH 32/34] avcodec/libtheoraenc: Avoid copying packet data

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Mon Apr 26 01:34:46 EEST 2021


Here the packet size is known before allocating the packet because
the encoder provides said information (and works with internal buffers
itself), so one can pass this information to ff_alloc_packet2() to
avoid the implicit use of another intermediate buffer for the packet data.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavcodec/libtheoraenc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavcodec/libtheoraenc.c b/libavcodec/libtheoraenc.c
index 16966ed433..5dd8c2084f 100644
--- a/libavcodec/libtheoraenc.c
+++ b/libavcodec/libtheoraenc.c
@@ -339,7 +339,8 @@ static int encode_frame(AVCodecContext* avc_context, AVPacket *pkt,
     }
 
     /* Copy ogg_packet content out to buffer */
-    if ((ret = ff_alloc_packet2(avc_context, pkt, o_packet.bytes, 0)) < 0)
+    if ((ret = ff_alloc_packet2(avc_context, pkt, o_packet.bytes,
+                                                  o_packet.bytes)) < 0)
         return ret;
     memcpy(pkt->data, o_packet.packet, o_packet.bytes);
 
-- 
2.27.0



More information about the ffmpeg-devel mailing list