[FFmpeg-devel] [PATCH 42/46] avcodec/videotoolboxenc: Avoid copying data, allow user-supplied buffers
Rick Kern
kernrj at gmail.com
Thu May 6 07:32:02 EEST 2021
On Thu, Apr 29, 2021 at 8:04 PM Andreas Rheinhardt <
andreas.rheinhardt at outlook.com> wrote:
> 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>
> ---
> This is completely untested (but actually also trivial). I hope someone
> can actually test it.
>
This works fine - applied.
>
> libavcodec/videotoolboxenc.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index e576ff7d7e..f3e66c9e06 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>
> @@ -1974,7 +1975,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;
>
> @@ -2017,7 +2018,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;
> }
> @@ -2664,12 +2664,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,
> @@ -2698,12 +2698,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,
> --
> 2.27.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>
More information about the ffmpeg-devel
mailing list