diff options
author | xufuji456 <839789740@qq.com> | 2023-05-19 14:05:14 +0800 |
---|---|---|
committer | Rick Kern <kernrj@gmail.com> | 2023-05-19 09:40:28 -0400 |
commit | 5cd304298eddbdc88d8c3c7d1bbf71aa251b096c (patch) | |
tree | 4316a60b26b07a932b493954440e3bbe4130c662 /libavcodec/videotoolboxenc.c | |
parent | 47430a3cb18c77f6c148eee7c528abc2e8bf3e91 (diff) |
avcodec/videotoolboxenc: add low-latency encoding
When using low-latency mode, it eliminates frame reordering
and follows a one-in-one-out encoding mode
Signed-off-by: xufuji456 <839789740@qq.com>
Signed-off-by: Rick Kern <kernrj@gmail.com>
Diffstat (limited to 'libavcodec/videotoolboxenc.c')
-rw-r--r-- | libavcodec/videotoolboxenc.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index c6f22723d6..e91d17c132 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -105,6 +105,7 @@ static struct{ CFStringRef kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder; CFStringRef kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder; + CFStringRef kVTVideoEncoderSpecification_EnableLowLatencyRateControl; getParameterSetAtIndex CMVideoFormatDescriptionGetHEVCParameterSetAtIndex; } compat_keys; @@ -171,6 +172,8 @@ static void loadVTEncSymbols(void){ "EnableHardwareAcceleratedVideoEncoder"); GET_SYM(kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder, "RequireHardwareAcceleratedVideoEncoder"); + GET_SYM(kVTVideoEncoderSpecification_EnableLowLatencyRateControl, + "EnableLowLatencyRateControl"); } typedef enum VT_H264Profile { @@ -1441,6 +1444,17 @@ static int vtenc_create_encoder(AVCodecContext *avctx, } } + // low-latency mode: eliminate frame reordering, follow a one-in-one-out encoding mode + if ((avctx->flags & AV_CODEC_FLAG_LOW_DELAY) && avctx->codec_id == AV_CODEC_ID_H264) { + status = VTSessionSetProperty(vtctx->session, + compat_keys.kVTVideoEncoderSpecification_EnableLowLatencyRateControl, + kCFBooleanTrue); + + if (status) { + av_log(avctx, AV_LOG_ERROR, "Error setting low latency property: %d\n", status); + } + } + status = VTCompressionSessionPrepareToEncodeFrames(vtctx->session); if (status) { av_log(avctx, AV_LOG_ERROR, "Error: cannot prepare encoder: %d\n", status); |