[FFmpeg-cvslog] avcodec/yuv4enc: Avoid copying packet data, allow user-supplied buffers
Andreas Rheinhardt
git at videolan.org
Wed May 5 15:38:47 EEST 2021
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Apr 25 01:43:26 2021 +0200| [a3f02388f169c6513c4f242a1cb4b507711eded7] | committer: Andreas Rheinhardt
avcodec/yuv4enc: 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=a3f02388f169c6513c4f242a1cb4b507711eded7
---
libavcodec/yuv4enc.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/libavcodec/yuv4enc.c b/libavcodec/yuv4enc.c
index 259395d9da..995c994b53 100644
--- a/libavcodec/yuv4enc.c
+++ b/libavcodec/yuv4enc.c
@@ -21,6 +21,7 @@
*/
#include "avcodec.h"
+#include "encode.h"
#include "internal.h"
static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
@@ -30,7 +31,9 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
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)
+ ret = ff_get_encode_buffer(avctx, pkt, 6 * (avctx->width + 1 >> 1)
+ * (avctx->height + 1 >> 1), 0);
+ if (ret < 0)
return ret;
dst = pkt->data;
@@ -62,6 +65,7 @@ const AVCodec ff_yuv4_encoder = {
.long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_YUV4,
+ .capabilities = AV_CODEC_CAP_DR1,
.encode2 = yuv4_encode_frame,
.pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
};
More information about the ffmpeg-cvslog
mailing list