diff mbox series

[FFmpeg-devel] lavc/libvpx: increase thread limit to 64

Message ID 20220928015149.1830-1-ovchinnikov.dmitrii@gmail.com
State New
Headers show
Series [FFmpeg-devel] lavc/libvpx: increase thread limit to 64 | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Dmitrii Ovchinnikov Sept. 28, 2022, 1:51 a.m. UTC
This change improves the performance and multicore scalability of the vp9
codec for streaming single-pass encoded videos by taking advantage of up
to 64 cores in the system. The current thread limit for ffmpeg codecs is 16 
(MAX_AUTO_THREADS in pthread_internal.h) due to a limitation in H.264 codec
that prevents more than 16 threads being used.

Our experiments show that increasing the thread limit to 64 for vp9 improves
the performance for encoding 4K raw videos for streaming by up to 47%
compared to 16 threads, and from 20-30% for 32 threads, with the same quality
as measured by the VMAF score.

Rationale for our change:
Vp9 uses tiling to split the video frame into multiple columns; tiles must
be at least 256 pixels wide, so there is a limit to how many tiles can be
used. The tiles can be processed in parallel, and more tiles mean more CPU
threads can be used. 4K videos can make use of 16 threads, and 8K videos
can use 32. Row-mt can double the number of threads so 64 threads can be used.

---
 libavcodec/libvpx.h    | 3 +++
 libavcodec/libvpxdec.c | 2 +-
 libavcodec/libvpxenc.c | 2 +-
 3 files changed, 5 insertions(+), 2 deletions(-)

Comments

Ronald S. Bultje Sept. 28, 2022, 2:12 a.m. UTC | #1
Hi,

On Tue, Sep 27, 2022 at 9:52 PM OvchinnikovDmitrii <
ovchinnikov.dmitrii@gmail.com> wrote:

> +/* Increase max threads for libvpx from 16 to 64 to benefit 4K/8K video
> encoding. */
>

The "increase" and "from 16 to" are not very helpful. Just documenting the
code that is, not what it was before, is generally good enough.

Ronald
diff mbox series

Patch

diff --git a/libavcodec/libvpx.h b/libavcodec/libvpx.h
index 0caed8cdcb..c0615e96a4 100644
--- a/libavcodec/libvpx.h
+++ b/libavcodec/libvpx.h
@@ -25,6 +25,9 @@ 
 
 #include "codec_internal.h"
 
+/* Increase max threads for libvpx from 16 to 64 to benefit 4K/8K video encoding. */
+#define MAX_VPX_THREADS 64
+
 void ff_vp9_init_static(FFCodec *codec);
 #if 0
 enum AVPixelFormat ff_vpx_imgfmt_to_pixfmt(vpx_img_fmt_t img);
diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
index c5b95332d3..819af47505 100644
--- a/libavcodec/libvpxdec.c
+++ b/libavcodec/libvpxdec.c
@@ -89,7 +89,7 @@  static av_cold int vpx_init(AVCodecContext *avctx,
                             const struct vpx_codec_iface *iface)
 {
     struct vpx_codec_dec_cfg deccfg = {
-        .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16)
+        .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), MAX_VPX_THREADS)
     };
 
     av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
index 5b7c7735a1..baa90957c5 100644
--- a/libavcodec/libvpxenc.c
+++ b/libavcodec/libvpxenc.c
@@ -939,7 +939,7 @@  static av_cold int vpx_init(AVCodecContext *avctx,
     enccfg.g_timebase.num = avctx->time_base.num;
     enccfg.g_timebase.den = avctx->time_base.den;
     enccfg.g_threads      =
-        FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16);
+        FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), MAX_VPX_THREADS);
     enccfg.g_lag_in_frames= ctx->lag_in_frames;
 
     if (avctx->flags & AV_CODEC_FLAG_PASS1)