Question / Help Set Affinity Via x264 Options to Force Separate Encodes on Seperate CPUs

Hi all,

I've been having some strange issues with OBS and I think it's due to the weird setup I have. I'm running a dual x5680 CPU system with 12 cores. I want to stream and record at the same time however, sometimes when I try to do both, OBS complains that the encoder is overloaded and both the stream and the recording start dropping frames. But the strange part is that this doesn't always happen. I can go 3+ hour streams while recording it without a single hitch and then at a different day start up the stream and recording only to immediately have issues.

Looking at CPU usage, it usually doesn't exceed 50%, and when I look at task manager, it looks like most of the activity is localized on one of the two CPUs. However when I switch from just streaming to streaming and recording it doesn't look like CPU usage is going up so the conclusion that I am coming to is that there is a fight for resources on one of the CPUs while the second one sits there not doing much.

So what I want to do is to have the stream encoded on one of the two CPUs and have the recording encoded on the other of the two CPUs. I was hoping that I could accomplish this by making use of the x264 options to force the affinity of the stream encode to cores 0-5 or threads 0-11 and to force the affinity of the recording encode to cores 6-11 or cores 12-23.

I know that you can force the affinity of OBS as a whole through some of the shortcut options but I don't think that's going to accomplish what I want because I want to separate the two encodes entirely.

Is something like this possible?

I've attached the log from the last stream that I did that had issues to this post, any help would be most appreciated!
 

Attachments

  • 2017-12-01 20-41-43.txt
    20.5 KB · Views: 88
I should add that I've attempted adding 'affinity 000FFF' and 'affinity FFF' as the arguments inside of the x264 options field to no avail. I'm not sure if I'm formatting these correctly, but it seems like ffmpeg has the option to set affinity in some manner like this.
 

sam686

Member
Try custom x264 option threads=12 (or less) for both recording and streaming.

I don't think OBS-Studio x264 have affinity option to limit thread to a few CPU cores.

Windows task manager can only do process, not threads.
A program called "Process Hacker" can limit thread affinity on each threads which might help, but do note that x264 may use multiple threads. (unless threads=1 is used but this will probably overload encoder) Encoding and/or live streaming may need to be on for threads to show up in "Process Hacker". It might need to be re-done everytime encoder starts.

But again, try threads=12 (or a little less) to see if that fixes the problem.
 
Unfortunately I've already tried that out, giving both 12 threads, or giving them varying amount of threads and I still get similar results where individually they work perfectly fine, never really exceeding 20-50% CPU usage but as soon as both of them are up and running I'm staying around 50% and the encoder is complaining that it's overloaded. But I'll look into process hacker to see if it can accomplish anything.
 

tronik

New Member
Hello,

I figured this out myself. To set the Affinity, some reference this thread:

https://www.eightforums.com/threads/cpu-affinity-shortcut-for-a-program-create-in-windows.40339/

You will need to read through it to learn how to convert the binary to hexadecimal that is needed in the shortcut or batch file you create to launch OBS.

I have a 16 core (i9 9900k), my hexadecimal is f (CPU0, CPU1, CPU2, CPU3)

The standard recommendation is to create a desktop shortcut... but there is an issue with this I mention below.

C:\Windows\System32\cmd.exe /c start “OBS Studio (64bit)” /affinity F “C:\Program Files\obs-studio\bin\64bit\obs64.exe”

When I open the shortcut, I get OBS gives me two error prompts

“Failed to find locale/en-US.ini”​
“Failed to load locale”​
I’ve noticed other forum discussions where people suggesting to cd to the OBS Studio directory. They were using a batch file. I opened up notepad and saved a file to my desktop called “obs.bat” and inserted the 2 lines below:
cd “C:\Program Files\obs-studio\bin\64bit\”​
C:\Windows\System32\cmd.exe /c start “OBS Studio” /affinity F “C:\Program Files\obs-studio\bin\64bit\obs64.exe”​
Now, I’m not sure how well optimize this will run… I’m streaming single PC, 720p at 60fps. I’d like to bump it to 1080p 60fps, however I don’t want to impact my game FPS or have OBS take a performance hit either.
Give this a try and let me know in the comments below how well it performs!
 

koala

Active Member
You don't need this batch file. You can use the start command directly. It has the parameter /D to change to the starting directory before actually starting the app:

start “OBS Studio” /D "C:\Program Files\obs-studio\bin\64bit" /affinity F "C:\Program Files\obs-studio\bin\64bit\obs64.exe"
 
Top