[FFmpeg-devel] [PATCH 38/46] avcodec/v408enc: Avoid copying packet data, allow user-supplied buffers

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Fri Apr 30 02:57:09 EEST 2021


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>
---
 libavcodec/v408enc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/libavcodec/v408enc.c b/libavcodec/v408enc.c
index 7df371f0ea..a0cda6fb0c 100644
--- a/libavcodec/v408enc.c
+++ b/libavcodec/v408enc.c
@@ -22,6 +22,7 @@
 
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
+#include "encode.h"
 #include "internal.h"
 
 static av_cold int v408_encode_init(AVCodecContext *avctx)
@@ -39,7 +40,8 @@ static int v408_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     uint8_t *y, *u, *v, *a;
     int i, j, ret;
 
-    if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4, 0)) < 0)
+    ret = ff_get_encode_buffer(avctx, pkt, avctx->width * avctx->height * 4, 0);
+    if (ret < 0)
         return ret;
     dst = pkt->data;
 
@@ -79,6 +81,7 @@ const AVCodec ff_ayuv_encoder = {
     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
     .type         = AVMEDIA_TYPE_VIDEO,
     .id           = AV_CODEC_ID_AYUV,
+    .capabilities = AV_CODEC_CAP_DR1,
     .init         = v408_encode_init,
     .encode2      = v408_encode_frame,
     .pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE },
@@ -90,6 +93,7 @@ const AVCodec ff_v408_encoder = {
     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
     .type         = AVMEDIA_TYPE_VIDEO,
     .id           = AV_CODEC_ID_V408,
+    .capabilities = AV_CODEC_CAP_DR1,
     .init         = v408_encode_init,
     .encode2      = v408_encode_frame,
     .pix_fmts     = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE },
-- 
2.27.0



More information about the ffmpeg-devel mailing list