Credit Andrew with recommending upgrade libvpx
[goodguy/cinelerra.git] / cinelerra-5.1 / thirdparty / src / ffmpeg-5.1.patchD
1 From c13d95934327ddad4db30f6aee93cd2aa6a26a57 Mon Sep 17 00:00:00 2001
2 From: OvchinnikovDmitrii <ovchinnikov.dmitrii@gmail.com>
3 Date: Thu, 6 Oct 2022 15:49:59 +0200
4 Subject: [PATCH 1/1] lavc/libvpx: increase thread limit to 64
5
6 This change improves the performance and multicore scalability of the vp9
7 codec for streaming single-pass encoded videos by taking advantage of up
8 to 64 cores in the system. The current thread limit for ffmpeg codecs is 16
9 (MAX_AUTO_THREADS in pthread_internal.h) due to a limitation in H.264 codec
10 that prevents more than 16 threads being used.
11
12 Experiments show that increasing the thread limit to 64 for vp9 improves
13 the performance for encoding 4K raw videos for streaming by up to 47%
14 compared to 16 threads, and from 20-30% for 32 threads, with the same quality
15 as measured by the VMAF score.
16
17 Rationale for this change:
18 Vp9 uses tiling to split the video frame into multiple columns; tiles must
19 be at least 256 pixels wide, so there is a limit to how many tiles can be
20 used. The tiles can be processed in parallel, and more tiles mean more CPU
21 threads can be used. 4K videos can make use of 16 threads, and 8K videos
22 can use 32. Row-mt can double the number of threads so 64 threads can be used.
23
24 Signed-off-by: James Zern <jzern@google.com>
25 ---
26  libavcodec/libvpx.h    | 2 ++
27  libavcodec/libvpxdec.c | 2 +-
28  libavcodec/libvpxenc.c | 2 +-
29  3 files changed, 4 insertions(+), 2 deletions(-)
30
31 diff --git a/libavcodec/libvpx.h b/libavcodec/libvpx.h
32 index 0caed8cdcb..331feb8745 100644
33 --- a/libavcodec/libvpx.h
34 +++ b/libavcodec/libvpx.h
35 @@ -25,6 +25,8 @@
36  
37  #include "codec_internal.h"
38  
39 +#define MAX_VPX_THREADS 64
40 +
41  void ff_vp9_init_static(FFCodec *codec);
42  #if 0
43  enum AVPixelFormat ff_vpx_imgfmt_to_pixfmt(vpx_img_fmt_t img);
44 diff --git a/libavcodec/libvpxdec.c b/libavcodec/libvpxdec.c
45 index 9cd2c56caf..0ae19c3f72 100644
46 --- a/libavcodec/libvpxdec.c
47 +++ b/libavcodec/libvpxdec.c
48 @@ -88,7 +88,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
49                              const struct vpx_codec_iface *iface)
50  {
51      struct vpx_codec_dec_cfg deccfg = {
52 -        .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16)
53 +        .threads = FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), MAX_VPX_THREADS)
54      };
55  
56      av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
57 diff --git a/libavcodec/libvpxenc.c b/libavcodec/libvpxenc.c
58 index 9aa5510c28..339d4d8146 100644
59 --- a/libavcodec/libvpxenc.c
60 +++ b/libavcodec/libvpxenc.c
61 @@ -942,7 +942,7 @@ static av_cold int vpx_init(AVCodecContext *avctx,
62      enccfg.g_timebase.num = avctx->time_base.num;
63      enccfg.g_timebase.den = avctx->time_base.den;
64      enccfg.g_threads      =
65 -        FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), 16);
66 +        FFMIN(avctx->thread_count ? avctx->thread_count : av_cpu_count(), MAX_VPX_THREADS);
67      enccfg.g_lag_in_frames= ctx->lag_in_frames;
68  
69      if (avctx->flags & AV_CODEC_FLAG_PASS1)
70 -- 
71 2.25.1
72