summaryrefslogtreecommitdiff
path: root/libavcodec/videotoolboxenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-04-30 01:57:13 +0200
committerRick Kern <kernrj@gmail.com>2021-05-06 00:29:36 -0400
commit7539a01bb0ea24998e1aa87706edf9785ddd3ac6 (patch)
treec0d99242c5647034774d342bdbbb2412a2a91fea /libavcodec/videotoolboxenc.c
parente10d75610c62fcc42ad8931a09abc73ee82caf82 (diff)
downloadffmpeg-7539a01bb0ea24998e1aa87706edf9785ddd3ac6.tar.gz
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@outlook.com> Signed-off-by: Rick Kern <kernrj@gmail.com>
Diffstat (limited to 'libavcodec/videotoolboxenc.c')
-rw-r--r--libavcodec/videotoolboxenc.c9
1 files 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,