[FFmpeg-devel] [PATCH] libavcodec/videotoolboxenc.c: add option to hevc encoder to prioritize speed.

Thilo Borgmann thilo.borgmann at mail.de
Thu Apr 14 11:13:16 EEST 2022


Hi,

Am 14.04.22 um 08:48 schrieb Simone Karin Lehmann:
> Somehow it seems, that this patch never got onto the mailing list. So may I kindly ask you to review it.
> 
> --
> Stay hungry, stay foolish
> 
>> Am 26.01.2022 um 17:31 schrieb Simone Karin Lehmann <simone at lisanet.de>:
>>
>> 
>> The patch adds an option to the hevc_videotoolbox encoder to prioritize speed for Macs with Apple Silicon CPU.
>>
>> This speeds up encodings up to 50% - 70%. In conjunction with the qcale option -q, visible quality will be unchanged. The increase in file size is very moderate, although still depending on the source material.
>>
>>
>> Signed-off-by: Simone Karin Lehmann <simone at lisanet.de>
>> ---
>> libavcodec/videotoolboxenc.c | 13 +++++++++++++
>> 1 file changed, 13 insertions(+)
>>
>> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
>> index 418ff00b8d..ab0dad6cbc 100644
>> --- a/libavcodec/videotoolboxenc.c
>> +++ b/libavcodec/videotoolboxenc.c
>> @@ -236,6 +236,7 @@ typedef struct VTEncContext {
>>      int allow_sw;
>>      int require_sw;
>>      double alpha_quality;
>> +    int64_t prio_speed;

int64_t is definitely overkill.

>>
>>      bool flushing;
>>      int has_b_frames;
>> @@ -1145,6 +1146,17 @@ static int vtenc_create_encoder(AVCodecContext   *avctx,
>>          return AVERROR_EXTERNAL;
>>      }
>>
>> +    // prioritize speed over quality
>> +    if (vtctx->prio_speed) {
>> +        status = VTSessionSetProperty(vtctx->session,
>> +                                      kVTCompressionPropertyKey_PrioritizeEncodingSpeedOverQuality,
>> +                                      kCFBooleanTrue);
>> +        if (status) {
>> +            av_log(avctx, AV_LOG_ERROR, "Error setting PrioritizeEncodingSpeedOverQuality property: %d\n", status);
>> +            return AVERROR_EXTERNAL;
>> +        }

If its called to priotize speed over qual, why not just print a warning and continue without this option?

>> +    }
>> +
>>      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;
>> @@ -2744,6 +2756,7 @@ static const AVOption hevc_options[] = {
>>      { "main10",   "Main10 Profile",   0, AV_OPT_TYPE_CONST, { .i64 = HEVC_PROF_MAIN10 }, INT_MIN, INT_MAX, VE, "profile" },
>>
>>      { "alpha_quality", "Compression quality for the alpha channel", OFFSET(alpha_quality), AV_OPT_TYPE_DOUBLE, { .dbl = 0.0 }, 0.0, 1.0, VE },
>> +    { "prio_speed", "prioritize encoding speed", OFFSET(prio_speed), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },

Just use an int.

Thanks,
Thilo


More information about the ffmpeg-devel mailing list