[FFmpeg-cvslog] avcodec/y41penc: Avoid copying packet data, allow user-supplied buffers

Andreas Rheinhardt git at videolan.org
Wed May 5 15:38:45 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 25 01:43:26 2021 +0200| [a043dcbe65efbc07d6f83b5822b99377035039a1] | committer: Andreas Rheinhardt

avcodec/y41penc: Avoid copying packet data, allow user-supplied buffers

When the packet size is known in advance like here, one can avoid
an intermediate buffer for the packet data by using
ff_get_encode_buffer() and also set AV_CODEC_CAP_DR1 at the same time.

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

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

 libavcodec/y41penc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libavcodec/y41penc.c b/libavcodec/y41penc.c
index e7d639008f..cd4c43b800 100644
--- a/libavcodec/y41penc.c
+++ b/libavcodec/y41penc.c
@@ -21,6 +21,7 @@
  */
 
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 
 static av_cold int y41p_encode_init(AVCodecContext *avctx)
@@ -43,7 +44,8 @@ static int y41p_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     uint8_t *y, *u, *v;
     int i, j, ret;
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 1.5, 0)) < 0)
+    ret = ff_get_encode_buffer(avctx, pkt, avctx->width * avctx->height * 1.5, 0);
+    if (ret < 0)
         return ret;
 
     dst = pkt->data;
@@ -80,6 +82,7 @@ const AVCodec ff_y41p_encoder = {
     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"),
     .type         = AVMEDIA_TYPE_VIDEO,
     .id           = AV_CODEC_ID_Y41P,
+    .capabilities = AV_CODEC_CAP_DR1,
     .init         = y41p_encode_init,
     .encode2      = y41p_encode_frame,
     .pix_fmts     = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV411P,



More information about the ffmpeg-cvslog mailing list