How to set the maximum number of threads used by svt-av1 encoder?

iiai snow

New Member
My CPU is Ryzen 9 5950X,I want use SVT-AV1 Encoder. But Minecraft's optimization is like a piece of shXt.Minecraft can't use multi threads very much.So,if I play Minecraft and use OBS-Studio in the same time,OBS is very normally but minecraft is only 25/8 fps and it can't usage the GPU very well and I cant use other encoder because they are work worster, in the 3840x2160 60fps HDR,If use x264 or QSV h.264/265 and Intel VAAPI is encoder overdrived and lost so much fps.And sometime,AMD VAAPI be mosaic,AOM AV1 is encoding overtime 5s and encoding stoped.So I have to use the SVT AV1 because only it is work normally.
So I want make restrictions to SVT AV1 so as to it only can use most 16 or 20 or 24 threads and give Minecraft some free threads to upper the fps and make my can do more things.
Thanks,very much.
 

MrCommunistGen

New Member
What other encoder settings are you using? AV1 is pretty CPU intensive to encode, and if your settings are too aggressive, you'll still run out of CPU resources. I suspect THAT is why Minecraft is running so slowly -- SVT-AV1 is using all the available CPU resources and minecraft can only run ~25fps with what is left over. The AOM-AV1 encoder is VERY slow, and SVT-AV1 is much faster... but it's still much slower than x264 or x265.

My main experience with SVT-AV1 is for archival video encoding, but I'll try to apply that knowledge to streaming. I'll include links to what I'm reading so you can do your own research if you want to better understand what I'm talking about.

From the SVT-AV1 documentation, here's their documentation on suggested usage with ffmpeg:
https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Ffmpeg.md

Notably, they recommend using preset 10 for realtime encoding (higher number presets are faster but produce worse quality output at a given bitrate). The list of all presets is here: https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/CommonQuestions.md#what-presets-do

I did some test encodes of a 1080p video file on a 5600G (the machine I'm on right now). 4K is 4x as many pixels as 1080p. Though the scaling won't be linear, I'd expect roughly 1/4 the encode fps at 4K using the same settings. If you're trying to also encode HDR (10-bit color) then there will be an additional slowdown. As a rough estimate, I'd expect another 10% decrease in encode fps.

Preset = 10, CRF = 30: 67 fps
Preset = 10, CRF = 30, 10-bit color: 61 fps
Preset = 11, CRF = 30, 10-bit color: 71 fps (note: CPU utilization was poor at ~70% of 12 threads)

Using the assumptions from above, I'd expect the 5600G using all 12 threads to be able to encode 4K HDR at ~15fps ( 61/4 ).
Using some more rough math, I'd expect that a 5950X capped at 20 threads will get roughly 25 fps*. 20/12 = 1.67 1.67*15 = 25
* Yes, I realize that a 5950X runs at higher clocks than a 5600G and will have somewhat higher perf... but the difference will end up being minor... not like 2x or anything.

Based on these estimates, a 5950X does not have enough performance to encode SVT-AV1 at 4K60 in HDR in realtime. I'd recommend you try 1440p or even 1080p to start with just to see if you can get your stream running smoothly before trying 4K.

Still, I'll continue with my explanation in case you find it useful.

To use any of the parameters not specifically implemented in ffmpeg (such as parameters for controlling how many threads it uses), you need to use:
-svtav1-params

and then pass in the parameters without dashes, in a : separated list. I know this is probably a bit confusing unless you're already familiar with how it works so I'll provide an example:

If you wanted to pass in CRF = 30 and preset = 10 as svtav1-params you'd write it like this:
Code:
-svtav1-params preset=10:crf=30
No dashes, no spaces, and use the : character instead of commas. To pass in more parameters, just add more, being sure to use : between parameters. If you're only passing in one parameter, you'd omit the :

For restricting thread count the section of their parameters documentation I think is most relevant is:
https://gitlab.com/AOMediaCodec/SVT...s/Parameters.md#appendix-a-encoder-parameters

The section mentions using --lp to restrict logical processors. I confirmed that this works with ffmpeg when passed using svtav1-params. I ran the following on a 5600G:
Code:
ffmpeg.exe -i test.mkv -c:v libsvtav1 -svtav1-params preset=10:crf=30:lp=2 svt_test.mkv

and while encoding it states:
Code:
Svt[info]: Number of logical cores available: 2
When I don't pass in lp=2, this normally says: Number of logical cores available: 12

FWIW, this yielded an encode speed of 31fps at ~30% CPU utilization on the 5600G (~3.6 cores), so you may need to experiment to see what value to use to achieve the desired CPU saturation on a 5950X. Also note: if you're using a really fast preset, the SVT-AV1 encoder may not be able to achieve good CPU utilization on a 16C/32T CPU.

TL;DR
SVT-AV1 is very CPU intensive. Even though the 5950X is fast, I don't think it's fast enough to encode 4K60 HDR in realtime. I've provided settings to use to cap SVT-AV1 to use fewer threads. I'd recommend trying 1440p first to see if you can get that performing acceptably before trying 4K.

I hope this is helpful.
 
Last edited:

iiai snow

New Member
What other encoder settings are you using? AV1 is pretty CPU intensive to encode, and if your settings are too aggressive, you'll still run out of CPU resources. I suspect THAT is why Minecraft is running so slowly -- SVT-AV1 is using all the available CPU resources and minecraft can only run ~25fps with what is left over. The AOM-AV1 encoder is VERY slow, and SVT-AV1 is much faster... but it's still much slower than x264 or x265.

My main experience with SVT-AV1 is for archival video encoding, but I'll try to apply that knowledge to streaming. I'll include links to what I'm reading so you can do your own research if you want to better understand what I'm talking about.

From the SVT-AV1 documentation, here's their documentation on suggested usage with ffmpeg:
https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/Ffmpeg.md

Notably, they recommend using preset 10 for realtime encoding (higher number presets are faster but produce worse quality output at a given bitrate). The list of all presets is here: https://gitlab.com/AOMediaCodec/SVT-AV1/-/blob/master/Docs/CommonQuestions.md#what-presets-do

I did some test encodes of a 1080p video file on a 5600G (the machine I'm on right now). 4K is 4x as many pixels as 1080p. Though the scaling won't be linear, I'd expect roughly 1/4 the encode fps at 4K using the same settings. If you're trying to also encode HDR (10-bit color) then there will be an additional slowdown. As a rough estimate, I'd expect another 10% decrease in encode fps.

Preset = 10, CRF = 30: 67 fps
Preset = 10, CRF = 30, 10-bit color: 61 fps
Preset = 11, CRF = 30, 10-bit color: 71 fps (note: CPU utilization was poor at ~70% of 12 threads)

Using the assumptions from above, I'd expect the 5600G using all 12 threads to be able to encode 4K HDR at ~15fps ( 61/4 ).
Using some more rough math, I'd expect that a 5950X capped at 20 threads will get roughly 25 fps*. 20/12 = 1.67 1.67*15 = 25
* Yes, I realize that a 5950X runs at higher clocks than a 5600G and will have somewhat higher perf... but the difference will end up being minor... not like 2x or anything.

Based on these estimates, a 5950X does not have enough performance to encode SVT-AV1 at 4K60 in HDR in realtime. I'd recommend you try 1440p or even 1080p to start with just to see if you can get your stream running smoothly before trying 4K.

Still, I'll continue with my explanation in case you find it useful.

To use any of the parameters not specifically implemented in ffmpeg (such as parameters for controlling how many threads it uses), you need to use:
-svtav1-params

and then pass in the parameters without dashes, in a : separated list. I know this is probably a bit confusing unless you're already familiar with how it works so I'll provide an example:

If you wanted to pass in CRF = 30 and preset = 10 as svtav1-params you'd write it like this:
Code:
-svtav1-params preset=10:crf=30
No dashes, no spaces, and use the : character instead of commas. To pass in more parameters, just add more, being sure to use : between parameters. If you're only passing in one parameter, you'd omit the :

For restricting thread count the section of their parameters documentation I think is most relevant is:
https://gitlab.com/AOMediaCodec/SVT...s/Parameters.md#appendix-a-encoder-parameters

The section mentions using --lp to restrict logical processors. I confirmed that this works with ffmpeg when passed using svtav1-params. I ran the following on a 5600G:
Code:
ffmpeg.exe -i test.mkv -c:v libsvtav1 -svtav1-params preset=10:crf=30:lp=2 svt_test.mkv

and while encoding it states:
Code:
Svt[info]: Number of logical cores available: 2
When I don't pass in lp=2, this normally says: Number of logical cores available: 12

FWIW, this yielded an encode speed of 31fps at ~30% CPU utilization on the 5600G (~3.6 cores), so you may need to experiment to see what value to use to achieve the desired CPU saturation on a 5950X. Also note: if you're using a really fast preset, the SVT-AV1 encoder may not be able to achieve good CPU utilization on a 16C/32T CPU.

TL;DR
SVT-AV1 is very CPU intensive. Even though the 5950X is fast, I don't think it's fast enough to encode 4K60 HDR in realtime. I've provided settings to use to cap SVT-AV1 to use fewer threads. I'd recommend trying 1440p first to see if you can get that performing acceptably before trying 4K.

I hope this is helpful.
Oh,Thank for your help
but my use profile only 11 or 12,and my cpu usage only 40%,catch screen is very fluent.But only Minecraft is very very slowly
And if I use AOM AV1,always,encoding timeout,stop catch and my Arc380 is useless
 

iiai snow

New Member
Oh,Thank for your help
but my use profile only 11 or 12,and my cpu usage only 40%,catch screen is very fluent.But only Minecraft is very very slowly
And if I use AOM AV1,always,encoding timeout,stop catch and my Arc380 is useless
My main GPU is 6900xt,but is a waste unless gaming.So I bought Arc A380,But Arc A380 Only can running in 4K 25Fps or 1080P 60Fps Whether I'm using VAAPI or QuickSync
6900XT Can use 4K60Fps VAAPI high profile,but sometime it maybe mosaic and 0.1 FPS.So I dont like use it
as for Libx264 I use the medium profile amd catch is work normal but Minecraft is slowly again
with regard to Minecraft is very slowly. I tried to adjust priorities.But its useless
 

MrCommunistGen

New Member
but my use profile only 11 or 12,and my cpu usage only 40%,catch screen is very fluent.But only Minecraft is very very slowly

OK. Since you aren't getting full CPU utilization, I don't expect that restricting SVT-AV1 to fewer threads using parameters will help - but I could be wrong. Since you mentioned that you're getting less than 50% CPU usage I have another idea: You might try messing with CPU affinity.

Theory:
One of the issues that could be causing poor performance is that OBS and Minecraft could be bouncing back and forth between CCD0 and CCD1 on the 5950X causing poor performance.

Test:
Set OBS to have core affinity (using Task Manager or one of the other tools that exists) to only be able to use the CPU threads on one of the CCDs. You could pick CPU0 - CPU15 (CCD0) or you could pick CPU16 - CPU31 (CCD1). Then, once Minecraft is launched, set its affinity to the opposite of what you set OBS to use. That way Minecraft has one CCD to use and OBS has another CCD to use and there should be no data going back and forth between the two CCDs to cause latency issues.

And if I use AOM AV1,always,encoding timeout,stop catch
Yeah, in my testing of AOM-AV1 compared to SVT-AV1, AOM is MUCH slower. Sometimes 10x slower. Since the AOM encoder is the reference encoder, it should, in some circumstances, provide better video quality than SVT-AV1. But, until CPUs get WAY faster I would never recommend using AOM-AV1 for any realtime encoding. I think the only reason they included it in OBS is to be thorough, since AFAIK AOM and SVT are the two most popular AV1 encoders.
 

MrCommunistGen

New Member
My main GPU is 6900xt,but is a waste unless gaming.So I bought Arc A380,But Arc A380 Only can running in 4K 25Fps or 1080P 60Fps Whether I'm using VAAPI or QuickSync
6900XT Can use 4K60Fps VAAPI high profile,but sometime it maybe mosaic and 0.1 FPS.So I dont like use it
as for Libx264 I use the medium profile amd catch is work normal but Minecraft is slowly again
with regard to Minecraft is very slowly. I tried to adjust priorities.But its useless
I have a 6800XT in my main rig (paired with the 5800X I referenced in my first post). I would agree that I've been disappointed in the quality of AMD's hardware encoder, but I don't do any streaming so it hasn't really affected me.

It's odd that the A380 struggles. I don't have any experience with it, but I would have expected it to be able to handle 4K60, based mostly on this video from Epos Vox: https://www.youtube.com/watch?v=bZjtoCBla1g. I watched it when it first came out and haven't had a chance to re-watch it, but I thought he said that 4K60 worked on the A380.
 

MrCommunistGen

New Member
Mmm. I guess I should double check. You're running the latest OBS 29.1 release, right? That just came out a couple days ago and may have improved some of the things you've had issues with.
 

iiai snow

New Member
OK. Since you aren't getting full CPU utilization, I don't expect that restricting SVT-AV1 to fewer threads using parameters will help - but I could be wrong. Since you mentioned that you're getting less than 50% CPU usage I have another idea: You might try messing with CPU affinity.

Theory:
One of the issues that could be causing poor performance is that OBS and Minecraft could be bouncing back and forth between CCD0 and CCD1 on the 5950X causing poor performance.

Test:
Set OBS to have core affinity (using Task Manager or one of the other tools that exists) to only be able to use the CPU threads on one of the CCDs. You could pick CPU0 - CPU15 (CCD0) or you could pick CPU16 - CPU31 (CCD1). Then, once Minecraft is launched, set its affinity to the opposite of what you set OBS to use. That way Minecraft has one CCD to use and OBS has another CCD to use and there should be no data going back and forth between the two CCDs to cause latency issues.


Yeah, in my testing of AOM-AV1 compared to SVT-AV1, AOM is MUCH slower. Sometimes 10x slower. Since the AOM encoder is the reference encoder, it should, in some circumstances, provide better video quality than SVT-AV1. But, until CPUs get WAY faster I would never recommend using AOM-AV1 for any realtime encoding. I think the only reason they included it in OBS is to be thorough, since AFAIK AOM and SVT are the two most popular AV1 encoders.
Oh It's useful and thank for your help
 
Top