Solved How to record desktop audio on OBS-Studio

Okay, so I've been at this for a while now. For context: I used to use Arch linux and I recall having to do some loopback command to listen to the output of my default sound device, thereby capturing my desktop audio to stream with in OBS. Since then, I switched to FreeBSD but also streamed from OBS on a separate (Windows) computer, using a capture card to capture the HDMI output. Now, I'm trying to set up OBS to stream from FreeBSD.

I have audio working on my system and I can pick up input from my headset mic (but I haven't figured out how to get audio from my webcam mic. A separate issue, but if I can get help with this too, that'd be great). I can't seem to figure out how to capture my desktop audio.

Like I mentioned, I used to do some kind of loopback to record the output sent to my default device, but I think I read on the forums that this isn't possible with oss (or there is a hacky way to do it with virtual_oss, but I couldn't get that to work. Can't find the thread).

I also tried to use ffmpeg to capture audio, but I could only figure out how to capture my mic input.

Does anyone have any idea how to capture desktop audio using OBS? I've provided a screenshot of what I have available (-sndio input, which is same as Audio Input Capture (OSS), that is my headset mic). Here is the output of cat /dev/sndstat:

Code:
Installed devices:
pcm0: <NVIDIA (0x009a) (HDMI/DP 8ch)> (play)
pcm1: <NVIDIA (0x009a) (HDMI/DP 8ch)> (play)
pcm2: <NVIDIA (0x009a) (HDMI/DP 8ch)> (play)
pcm3: <NVIDIA (0x009a) (HDMI/DP 8ch)> (play)
pcm4: <Realtek ALC1220 (Rear Analog 5.1/2.0)> (play/rec)
pcm5: <Realtek ALC1220 (Front Analog)> (play/rec)
pcm6: <Realtek ALC1220 (Rear Digital)> (play)
pcm7: <USB audio> (rec)
pcm8: <USB audio> (play/rec) default
No devices installed from userspace.

Please let me know what other information you might need. Thank you in advanced!
 

Attachments

  • 2021-10-11-224655_820x246_scrot.png
    2021-10-11-224655_820x246_scrot.png
    30.9 KB · Views: 221
I have been playing around with some audio and OBS on FreeBSD lately, so I have an idea on where to start, but nothing specific for your issue. Since what you are encountering sounds like a situation I may encounter, I'll look into it and try some things out, but it might be a bit before I can come up with anything as I am very busy this week.

I'd suggest to start reading through through sound() and mixer() man pages for some ideas. Especially look at the sysctl options in sound ().
 
I have audio working on my system and I can pick up input from my headset mic (but I haven't figured out how to get audio from my webcam mic. A separate issue, but if I can get help with this too, that'd be great). I can't seem to figure out how to capture my desktop audio.
Screenshot from 2021-10-12 21-16-37.png


You need to select the desktop audio as a source.
 
Here is the output of cat /dev/sndstat
Your default output device is pcm8 now, this is where your desktop audio most likely goes now. You can change the default device with a line hw.snd.default_unit=N in /etc/sysctl.conf, where N is the trailing number of the pcm device. You may want to add another line hw.snd.verbose=2 there, command cat /dev/sndstat will show more detailed output then.

Device pcm8 (your headset?) is the default here. It corresponds to /dev/dsp8. I have absolutely no idea what OBS is, can't help you with that. Recording however is quite easy using OSS. I'm recording a Top 1000 these days using this command: /usr/local/bin/ffmpeg -y -f oss -i /dev/dsp4 -ac 2 -f flac /mnt//music/temp/slam.flac.
 
I can't seem to figure out how to capture my desktop audio.

The basic oss sound system of FreeBSD does not support output of your own system sound for recording or anything like that. There is a trick in another thread how to make this possible. https://forums.freebsd.org/threads/how-to-recored-audio-from-game-on-freebsd.77855


The other way is to use pulseaudio systemwide by setting all your applications to use pulseaudio as far as possible. Most ports do not have pulseaudio support enabled by default (so you have to recompile them) or do not have it at all.
 
Awesome, thank you all for the responses so far.
You need to select the desktop audio as a source.
I don't have this option in OBS so I'm not sure how you got this.

I'm going to look through the man pages and take a look at that other thread.

The other way is to use pulseaudio systemwide by setting all your applications to use pulseaudio as far as possible. Most ports do not have pulseaudio support enabled by default (so you have to recompile them) or do not have it at all.
I hope I don't have to resort to this, but if I do, I'm not sure how to see what all applications I would need to recompile to use pulseaudio or if I would recompile as needed. Wouldn't it depend on the application if there is a compile option to use pulseaudio, or is there a standard compile option I can use?
 
Update: My audio is no longer working and I'm trying to figure out what happened. I left my computer on overnight with OBS running (and all my other applications) and I found Youtube gave me some kind of "Audio something error. Please restart". Restarted. No audio.

I added a few things to my /boot/loader.conf:

efi_max_resolution="5120x1440"
aesni_load="YES"
geom_eli_load="YES"
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
zfs_load="YES"
nvidia_load="YES"
fuse_load="YES"
sound_load="YES"
snd_driver_load="YES"
snd_uaudio_load="YES"
snd_hda_load="YES"
sysctlinfo_load="YES"
cuse_load="YES"
Don't think any of that's the reason, however. Added dmesg.txt file as well.
Error message I get when attempting cat file.txt > /dev/dsp:

<W> fish: An error occurred while redirecting file '/dev/dsp'
open: Operation not supported
Investigating...

EDIT: Nevermind I was outputting to the wrong device. Tieks was right, pcm8 was my headset and I think pcm7 was my mic. Which was weird, because I'm fairly certain it was the other way around at one point.
 

Attachments

  • dmesg.txt
    12.8 KB · Views: 176
Some progress made.
OBS depends on PulseAudio, thus you are able to record sound from applications using PulseAudio.
This made me read through the PulseAudio manual, where I found a loopback option:
pulseaudio --load="module-loopback" -D

This was after I killall pulseaudio. Using pavucontrol, I was able to see now a "Loopback to /dev/dsp8 from..." under the Recording tab. Next to it was a drop down with all my devices + Monitor of device. Unfortunately, this doesn't seem to work. I play music but I don't see any activity from the volume monitor.

I also realized I have a separate issue with OBS. I have been starting it via the command line with doas obs, because apparently I have to be root to access my webcam. Starting as user, I no longer have access to my webcam, but the devices show up under audio sources. However, no audio activity seems to come through, just as in pavucontrol.

It occurs to me that I'm probably playing audio through OSS, which is why pulseaudio see's no activity. I guess I should use pulseaudio system-wide? I see a --system option for pulseaudio, but it says it's "generally not recommended unless the system knows no local users (e.g. is a thin client)." As a local user, I feel this warning is intended for me.

Edit: still reading through the other thread...
 

Attachments

  • 2021-10-12-214408_869x672_scrot.png
    2021-10-12-214408_869x672_scrot.png
    44.6 KB · Views: 183
I don't use OBS Studio but recording audio played from other applications should be possible through audio/sndio or audio/jack, as long as the involved applications have the corresponding backend. I see OBS Studio has both (as well as PulseAudio) enabled by default. Same with Firefox for example.
 
Nice. Okay, the webcam works fine now after adding myself to the `webcamd` group and restarting.
For what it's worth, after pulseaudio (I have it configured to not automatically spawn):

View attachment 11740
Awesome! So that seemed to do the trick (kind of). I had OBS open but under Global Audio Devices settings, they were all Disabled. I started `pulseaudio` and now I have access to all my devices. However, no audio seems to be coming through them.

Alexander88207 already mentioned that I should use pulseaudio system wide by setting it per-application; is there any other way to set pulseaudio as my default sound system?
 
There's really only 2 applications I have that I'm concerned about capturing sound for: spotifyd and chromium. I don't really see a way to set the audio backend for chrome, but spotifyd has an option which says:
-b, --backend <string> The audio backend to use [possible values: portaudio]
 

Re: <https://www.freshports.org/www/chromium/#config> you can build, for yourself, a package with PULSEAUDIO=on

Ports such as Chromium can take a surprisingly long time to build. I recommend ports-mgmt/poudriere-devel and poudriere-bulk(8) option -b to prefetch as many binaries as possible, to not waste your time. Discussions of alternatives to poudriere are scattered throughout the forums.

Afterthought

With SNDIO=on by default in both OBS Studio <https://www.freshports.org/multimedia/obs-studio/#config> and Chromium, maybe you need to configure something for sndio to do what's required. Then, no need to build Chromium or whatever.

 
Awesome, thanks everyone for the help. I was able to compile spotifyd with pulseaudio support and have confirmed that I am now able to capture audio from it in OBS. I'll look into poudriere (suprised I haven't yet) but I'm sure the same thing will work for chromium, so I'm marking this as solved now. Cheers!
 
Back
Top