From 9b80a61d9f9cb32e7dc9b2d67f663cb10be3f75a Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Tue, 29 Nov 2022 16:12:01 +0100 Subject: [PATCH] lavc: do not enable MT with CAP_OTHER_THREADS Only enable for libvpx*. Codecs must be individually evaluated - for libx265, it increases latency because it uses frame threading parallelism internally. For libsvt_hevc and libx264, the performance boost is not noticeable. --- src/video_compress/libavcodec.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/video_compress/libavcodec.cpp b/src/video_compress/libavcodec.cpp index 0b5559795..ec4707574 100644 --- a/src/video_compress/libavcodec.cpp +++ b/src/video_compress/libavcodec.cpp @@ -1692,8 +1692,10 @@ static void set_codec_thread_mode(AVCodecContext *codec_ctx, struct setparam_par if (req_thread_count != -1) { codec_ctx->thread_count = req_thread_count; } else if ((codec_ctx->codec->capabilities & AV_CODEC_CAP_OTHER_THREADS) != 0) { - // mainly for libvpx-vp9, libx264 has thread_count set implicitly to 0 (auto) - codec_ctx->thread_count = 0; + // do not enable MT for eg. libx265 - libx265 uses frame threads + if (strncmp(codec_ctx->codec->name, "libvpx", 6)) { + codec_ctx->thread_count = 0; + } } else if (codec_ctx->thread_type != 0) { codec_ctx->thread_count = thread::hardware_concurrency(); }