Question / Help Can you please explain x264 option, threads=?

awolive

Member
I currently have a 1950X Threadripper 16 core 32 thread processor and I would like to understand more about the advance options such as threads=? I was advised to use threads=80 and threads=0 but what do these mean and what should I be using for such a processor? I'm trying to fully max my CPU usage for encoding but also not bog down my FPS in-game. Thanks. Currently I can run 1080p60 @ 6k bit-rate, preset Slow/Slower with threads=80 with around 45-80% CPU usage.

Also, I've read using more than 22 or 24 threads for OBS actually hurts quality. Can please explain? Thanks
 

sam686

Member
threads=0 is x264 default number of threads.

Too many x264 threads increases latency and have more encoding memory usage. Too many x264 threads can hurt quality in constant bitrate mode and near-constant bitrate mode called VBV (video buffer verifier), due to increased encode delay. Keyframes need more data then other frame types to avoid pulsing poor quality keyframes.

Zero-delay or sliced thread mode have no delay, but this option farther worsen multi-threads quality.

In constant quality mode (no zero-delay nor sliced thread), there seem to be too little difference of quality with too many threads. But, live streaming requires constant bitrate or VBV mode.
 

awolive

Member
thanks for the fast reply! So when I tell OBS threads=80, does that mean use 80 physical threads or 80% of my available threads? I'm a little confused. Thank you
 

sam686

Member
threads=80 means it will use 80 threads for x264 encoding... but your CPU don't have that many threads which might slow things down more then just using 32 threads this CPU have.

Too little number of x264 threads (threads=1) can cause x264 encoder to get overloaded and drop/duplicate frames.
 

awolive

Member
perfect! thank you so much. I will experiment now when I get home. Any other tips I can play with or adjust to improve my quality with pixelation with a lot of artifacts being introduced when gaming?
 
If you were to use Threads=6-10 you would have far better results. For recording I would use CRF=10 with the lowest preset you can run without tanking frames, for streaming as long as you have the bandwidth allowance push the bitrate, it ultimately determines your quality overall.
 

awolive

Member
thanks a bunch man! I'll try that
so just be to clear try "threads=6-10"under x264 options or specially each number "threads=x" x=6,7,8,9,10 and test each one out.
 

RytoEX

Forum Admin
Forum Moderator
Developer
I currently have a 1950X Threadripper 16 core 32 thread processor and I would like to understand more about the advance options such as threads=? I was advised to use threads=80 and threads=0
I'd be curious to know where you heard that you should use threads=80.

Using threads=0 is the "auto" setting to allow x264 to select an "optimal" thread count, and is usually okay for normal use. I've seen a few quotes that auto uses "1.5 x number of cores for frame threads. 1 x number of cores for slice threads." Unfortunately, I don't know enough about x264 or threading to clarify that statement further.
 

sam686

Member
Using threads=0 is the "auto" setting to allow x264 to select an "optimal" thread count, and is usually okay for normal use. I've seen a few quotes that auto uses "1.5 x number of cores for frame threads. 1 x number of cores for slice threads."
This is in the x264 source code.
https://github.com/mirror/x264/blob/master/encoder/encoder.c
Line 539 (or near it as some lines might be added or moved after this reply.)
h->param.i_threads = x264_cpu_num_processors() * (h->param.b_sliced_threads?2:3)/2;

If default is used, threads*1.5 might be there as some threads gets their work done early.

Streaming and recording can have separate encoders with separate settings, or can share a single encoder by choosing recording as "use stream encoder". With 2 separate x264 encoders, might want to limit each encoders to smaller number of threads like threads=16 for each x264 encoders.

Limiting threads is also good for playing and streaming on the same computer. Might want to increase OBS-Studio priority (high or above normal) in OBS-Studio advanced settings.
 

bobhumplick

New Member
This is in the x264 source code.
https://github.com/mirror/x264/blob/master/encoder/encoder.c
Line 539 (or near it as some lines might be added or moved after this reply.)
h->param.i_threads = x264_cpu_num_processors() * (h->param.b_sliced_threads?2:3)/2;

If default is used, threads*1.5 might be there as some threads gets their work done early.

Streaming and recording can have separate encoders with separate settings, or can share a single encoder by choosing recording as "use stream encoder". With 2 separate x264 encoders, might want to limit each encoders to smaller number of threads like threads=16 for each x264 encoders.

Limiting threads is also good for playing and streaming on the same computer. Might want to increase OBS-Studio priority (high or above normal) in OBS-Studio advanced settings.

is there anyway you could explain this line of code? it looks like it is geting the number of logical cores (threads) and then ..... 2:3 ? is that a ratio? like log cores times 2 thirds divided by half? that doesnt sound right. i must be reading it wrong.

what thread count would you recommend for a poor 8700k trying to play and stream a game at the same time? 6 threads (leaving 6 log cores for the game?) maybe a bit mroe or a bit less?
 
is there anyway you could explain this line of code? it looks like it is geting the number of logical cores (threads) and then ..... 2:3 ? is that a ratio? like log cores times 2 thirds divided by half? that doesnt sound right. i must be reading it wrong.

what thread count would you recommend for a poor 8700k trying to play and stream a game at the same time? 6 threads (leaving 6 log cores for the game?) maybe a bit mroe or a bit less?

That's a conditional statement - if b_sliced_threads is set to true, then use 2, otherwise use 3. So by default x264 uses the exact number of logical processors if sliced threads is enabled, or 1.5 times that number if it's disabled. IIRC sliced threads are only enabled when zerolatency is selected as tuning though.
 
Top