summaryrefslogtreecommitdiff
path: root/libavcodec/videotoolboxenc.c
diff options
context:
space:
mode:
authorSimone Karin Lehmann <simone@lisanet.de>2022-05-01 21:07:47 +0200
committerRick Kern <kernrj@gmail.com>2022-05-02 08:10:22 -0700
commitb67572c7c707d508b15ce0543519208cf5d1fcfb (patch)
treebf731a0335b4ca759600db2aefc4c3ccc1a06d82 /libavcodec/videotoolboxenc.c
parent4d52d8c9f6a7fb5c035aff8cfeb8774a1de1123c (diff)
lavc/videotoolboxenc: Speed/Quality prioriry setting
Add options to h264, hevc and prores encoders to prioritize speed. Speeds up encoding by 50% - 70% Signed-off-by: Simone Karin Lehmann <simone@lisanet.de> Signed-off-by: Rick Kern <kernrj@gmail.com>
Diffstat (limited to 'libavcodec/videotoolboxenc.c')
-rw-r--r--libavcodec/videotoolboxenc.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
index 270496b7a7..69d9fe75bf 100644
--- a/libavcodec/videotoolboxenc.c
+++ b/libavcodec/videotoolboxenc.c
@@ -100,6 +100,7 @@ static struct{
CFStringRef kVTCompressionPropertyKey_RealTime;
CFStringRef kVTCompressionPropertyKey_TargetQualityForAlpha;
+ CFStringRef kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality;
CFStringRef kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder;
CFStringRef kVTVideoEncoderSpecification_RequireHardwareAcceleratedVideoEncoder;
@@ -161,6 +162,8 @@ static void loadVTEncSymbols(){
GET_SYM(kVTCompressionPropertyKey_RealTime, "RealTime");
GET_SYM(kVTCompressionPropertyKey_TargetQualityForAlpha,
"TargetQualityForAlpha");
+ GET_SYM(kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality,
+ "PrioritizeEncodingSpeedOverQuality");
GET_SYM(kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,
"EnableHardwareAcceleratedVideoEncoder");
@@ -237,6 +240,7 @@ typedef struct VTEncContext {
int allow_sw;
int require_sw;
double alpha_quality;
+ int prio_speed;
bool flushing;
int has_b_frames;
@@ -1146,6 +1150,15 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
return AVERROR_EXTERNAL;
}
+ if (vtctx->prio_speed >= 0) {
+ status = VTSessionSetProperty(vtctx->session,
+ compat_keys.kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality,
+ vtctx->prio_speed ? kCFBooleanTrue : kCFBooleanFalse);
+ if (status) {
+ av_log(avctx, AV_LOG_WARNING, "PrioritizeEncodingSpeedOverQuality property is not supported on this device. Ignoring.\n");
+ }
+ }
+
if ((vtctx->codec_id == AV_CODEC_ID_H264 || vtctx->codec_id == AV_CODEC_ID_HEVC)
&& max_rate > 0) {
bytes_per_second_value = max_rate >> 3;
@@ -2682,7 +2695,9 @@ static const enum AVPixelFormat prores_pix_fmts[] = {
{ "frames_before", "Other frames will come before the frames in this session. This helps smooth concatenation issues.", \
OFFSET(frames_before), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
{ "frames_after", "Other frames will come after the frames in this session. This helps smooth concatenation issues.", \
- OFFSET(frames_after), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
+ OFFSET(frames_after), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE }, \
+ { "prio_speed", "prioritize encoding speed", OFFSET(prio_speed), AV_OPT_TYPE_BOOL, \
+ { .i64 = -1 }, -1, 1, VE }, \
#define OFFSET(x) offsetof(VTEncContext, x)
static const AVOption h264_options[] = {