[FFmpeg-devel] [PATCH 22/34] avcodec/yuv4enc: Avoid copying packet data

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


When the packet size is known in advance like here, one can avoid
an intermediate buffer for the packet data.

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

diff --git a/libavcodec/yuv4enc.c b/libavcodec/yuv4enc.c
index 63a7fae964..5096f81e1a 100644
--- a/libavcodec/yuv4enc.c
+++ b/libavcodec/yuv4enc.c
@@ -26,11 +26,12 @@
 static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
                              const AVFrame *pic, int *got_packet)
 {
+    int64_t size = 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1);
     uint8_t *dst;
     uint8_t *y, *u, *v;
     int i, j, ret;
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1), 0)) < 0)
+    if ((ret = ff_alloc_packet2(avctx, pkt, size, size)) < 0)
         return ret;
     dst = pkt->data;
 
-- 
2.27.0



More information about the ffmpeg-devel mailing list