mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-06-04 05:57:49 +02:00
lavc/videotoolboxenc: Handle hwaccel format as input
Handle AV_PIX_FMT_VIDEOTOOLBOX. This results in better energy usage and faster encoding, especially on iOS. When the buffer comes from the media server, no memcpy's are needed. Signed-off-by: Rick Kern <kernrj@gmail.com>
This commit is contained in:
parent
d7cf3610c2
commit
0d4bf3074d
@ -621,11 +621,15 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
|
|||||||
CFDictionarySetValue(enc_info, kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, kCFBooleanTrue);
|
CFDictionarySetValue(enc_info, kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, kCFBooleanTrue);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (avctx->pix_fmt != AV_PIX_FMT_VIDEOTOOLBOX) {
|
||||||
status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info);
|
status = create_cv_pixel_buffer_info(avctx, &pixel_buffer_info);
|
||||||
if (status) {
|
if (status) {
|
||||||
CFRelease(enc_info);
|
CFRelease(enc_info);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pixel_buffer_info = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
status = VTCompressionSessionCreate(
|
status = VTCompressionSessionCreate(
|
||||||
kCFAllocatorDefault,
|
kCFAllocatorDefault,
|
||||||
@ -659,7 +663,7 @@ static av_cold int vtenc_init(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CFRelease(pixel_buffer_info);
|
if (pixel_buffer_info) CFRelease(pixel_buffer_info);
|
||||||
CFRelease(enc_info);
|
CFRelease(enc_info);
|
||||||
|
|
||||||
if (status || !vtctx->session) {
|
if (status || !vtctx->session) {
|
||||||
@ -1227,6 +1231,17 @@ static int create_cv_pixel_buffer(AVCodecContext *avctx,
|
|||||||
CVPixelBufferPoolRef pix_buf_pool;
|
CVPixelBufferPoolRef pix_buf_pool;
|
||||||
VTEncContext* vtctx = avctx->priv_data;
|
VTEncContext* vtctx = avctx->priv_data;
|
||||||
|
|
||||||
|
|
||||||
|
if (avctx->pix_fmt == AV_PIX_FMT_VIDEOTOOLBOX) {
|
||||||
|
av_assert0(frame->format == AV_PIX_FMT_VIDEOTOOLBOX);
|
||||||
|
|
||||||
|
*cv_img = (CVPixelBufferRef)frame->data[3];
|
||||||
|
av_assert0(*cv_img);
|
||||||
|
|
||||||
|
CFRetain(*cv_img);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
memset(widths, 0, sizeof(widths));
|
memset(widths, 0, sizeof(widths));
|
||||||
memset(heights, 0, sizeof(heights));
|
memset(heights, 0, sizeof(heights));
|
||||||
memset(strides, 0, sizeof(strides));
|
memset(strides, 0, sizeof(strides));
|
||||||
@ -1423,6 +1438,7 @@ static av_cold int vtenc_close(AVCodecContext *avctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const enum AVPixelFormat pix_fmts[] = {
|
static const enum AVPixelFormat pix_fmts[] = {
|
||||||
|
AV_PIX_FMT_VIDEOTOOLBOX,
|
||||||
AV_PIX_FMT_NV12,
|
AV_PIX_FMT_NV12,
|
||||||
AV_PIX_FMT_YUV420P,
|
AV_PIX_FMT_YUV420P,
|
||||||
AV_PIX_FMT_NONE
|
AV_PIX_FMT_NONE
|
||||||
|
Loading…
x
Reference in New Issue
Block a user