[FFmpeg-cvslog] lavc/videotoolboxenc: Speed/Quality prioriry setting

Simone Karin Lehmann git at videolan.org
Mon May 2 18:11:26 EEST 2022


ffmpeg | branch: master | Simone Karin Lehmann <simone at lisanet.de> | Sun May  1 21:07:47 2022 +0200| [b67572c7c707d508b15ce0543519208cf5d1fcfb] | committer: Rick Kern

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 at lisanet.de>
Signed-off-by: Rick Kern <kernrj at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b67572c7c707d508b15ce0543519208cf5d1fcfb
---

 libavcodec/videotoolboxenc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

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[] = {



More information about the ffmpeg-cvslog mailing list