summaryrefslogtreecommitdiffstats
path: root/contrib/ffmpeg
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2020-08-23 08:38:59 +0200
committerDamiano Galassi <[email protected]>2020-08-23 08:38:59 +0200
commitcecbabdb13ca517eb061f745138cbbe46092aad8 (patch)
tree3bf78e576f6adbbe7db477ea829bbe8d245c3395 /contrib/ffmpeg
parent350ab4509e124e02cc601cb07260eb9817045836 (diff)
libhb: improve videotoolbox detection and add support for constant quality encoding mode when available.
Diffstat (limited to 'contrib/ffmpeg')
-rw-r--r--contrib/ffmpeg/A20-videotoolbox-quality.patch51
1 files changed, 51 insertions, 0 deletions
diff --git a/contrib/ffmpeg/A20-videotoolbox-quality.patch b/contrib/ffmpeg/A20-videotoolbox-quality.patch
new file mode 100644
index 000000000..9c38fcd56
--- /dev/null
+++ b/contrib/ffmpeg/A20-videotoolbox-quality.patch
@@ -0,0 +1,51 @@
+diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
+index ff33c27..e13c85a 100644
+--- a/libavcodec/videotoolboxenc.c
++++ b/libavcodec/videotoolboxenc.c
+@@ -982,7 +982,9 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
+ VTEncContext *vtctx = avctx->priv_data;
+ SInt32 bit_rate = avctx->bit_rate;
+ SInt32 max_rate = avctx->rc_max_rate;
++ Float32 quality = avctx->global_quality;
+ CFNumberRef bit_rate_num;
++ CFNumberRef quality_num;
+ CFNumberRef bytes_per_second;
+ CFNumberRef one_second;
+ CFArrayRef data_rate_limits;
+@@ -1013,15 +1015,28 @@ static int vtenc_create_encoder(AVCodecContext *avctx,
+ return AVERROR_EXTERNAL;
+ }
+
+- bit_rate_num = CFNumberCreate(kCFAllocatorDefault,
+- kCFNumberSInt32Type,
+- &bit_rate);
+- if (!bit_rate_num) return AVERROR(ENOMEM);
++ if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
++ quality = quality / 100;
++ quality_num = CFNumberCreate(kCFAllocatorDefault,
++ kCFNumberFloat32Type,
++ &quality);
++ if (!quality_num) return AVERROR(ENOMEM);
+
+- status = VTSessionSetProperty(vtctx->session,
+- kVTCompressionPropertyKey_AverageBitRate,
+- bit_rate_num);
+- CFRelease(bit_rate_num);
++ status = VTSessionSetProperty(vtctx->session,
++ kVTCompressionPropertyKey_Quality,
++ quality_num);
++ CFRelease(quality_num);
++ } else {
++ bit_rate_num = CFNumberCreate(kCFAllocatorDefault,
++ kCFNumberSInt32Type,
++ &bit_rate);
++ if (!bit_rate_num) return AVERROR(ENOMEM);
++
++ status = VTSessionSetProperty(vtctx->session,
++ kVTCompressionPropertyKey_AverageBitRate,
++ bit_rate_num);
++ CFRelease(bit_rate_num);
++ }
+
+ if (status) {
+ av_log(avctx, AV_LOG_ERROR, "Error setting bitrate property: %d\n", status);