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

Andreas Rheinhardt git at videolan.org
Thu May 6 07:30:21 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Apr 30 01:57:13 2021 +0200| [7539a01bb0ea24998e1aa87706edf9785ddd3ac6] | committer: Rick Kern

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

Here the packet size is known before allocating the packet because
the encoder provides said information (and works with internal buffers
itself), so one use this information to avoid the implicit use of another
intermediate buffer for the packet data; and by switching to
ff_get_encode_buffer() one can also allow user-supplied buffers.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
Signed-off-by: Rick Kern <kernrj at gmail.com>

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

 libavcodec/videotoolboxenc.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index e4f890f7f7..58239e0ab9 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -32,6 +32,7 @@
 #include "internal.h"
 #include <pthread.h>
 #include "atsc_a53.h"
+#include "encode.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include <dlfcn.h>
@@ -1978,7 +1979,7 @@ static int vtenc_cm_to_avpacket(
                    sei_nalu_size +
                    nalu_count * ((int)sizeof(start_code) - (int)length_code_size);
 
-    status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size);
+    status = ff_get_encode_buffer(avctx, pkt, out_buf_size, 0);
     if (status < 0)
         return status;
 
@@ -2021,7 +2022,6 @@ static int vtenc_cm_to_avpacket(
     time_base_num = avctx->time_base.num;
     pkt->pts = pts.value / time_base_num;
     pkt->dts = dts.value / time_base_num - dts_delta;
-    pkt->size = out_buf_size;
 
     return 0;
 }
@@ -2668,12 +2668,12 @@ const AVCodec ff_h264_videotoolbox_encoder = {
     .long_name        = NULL_IF_CONFIG_SMALL("VideoToolbox H.264 Encoder"),
     .type             = AVMEDIA_TYPE_VIDEO,
     .id               = AV_CODEC_ID_H264,
+    .capabilities     = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
     .priv_data_size   = sizeof(VTEncContext),
     .pix_fmts         = avc_pix_fmts,
     .init             = vtenc_init,
     .encode2          = vtenc_frame,
     .close            = vtenc_close,
-    .capabilities     = AV_CODEC_CAP_DELAY,
     .priv_class       = &h264_videotoolbox_class,
     .caps_internal    = FF_CODEC_CAP_INIT_THREADSAFE |
                         FF_CODEC_CAP_INIT_CLEANUP,
@@ -2702,12 +2702,13 @@ const AVCodec ff_hevc_videotoolbox_encoder = {
     .long_name        = NULL_IF_CONFIG_SMALL("VideoToolbox H.265 Encoder"),
     .type             = AVMEDIA_TYPE_VIDEO,
     .id               = AV_CODEC_ID_HEVC,
+    .capabilities     = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY |
+                        AV_CODEC_CAP_HARDWARE,
     .priv_data_size   = sizeof(VTEncContext),
     .pix_fmts         = hevc_pix_fmts,
     .init             = vtenc_init,
     .encode2          = vtenc_frame,
     .close            = vtenc_close,
-    .capabilities     = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE,
     .priv_class       = &hevc_videotoolbox_class,
     .caps_internal    = FF_CODEC_CAP_INIT_THREADSAFE |
                         FF_CODEC_CAP_INIT_CLEANUP,



More information about the ffmpeg-cvslog mailing list