# Capturing audio with ffmpeg and ALSA is pretty much straightforward



## balanga (Jun 17, 2019)

According to https://trac.ffmpeg.org/wiki/Capture/ALSA .....

Capturing audio with ffmpeg and ALSA is pretty much straightforward:

```
ffmpeg -f alsa <input_options> -i <input_device> ... output.wav
```
Apparently that is all you need...

How do you do this on FreeBSD? I've been trying for almost a week and have not got anywhere... Seems like getting sound set up on FreeBSD can be troublesome. The Handbook is not really very useful in this regard....

How does ALSA, OSS, Pulseaudio etc fit into the whole picture?


----------



## zirias@ (Jun 17, 2019)

Huh? As simple as

```
ffmpeg -f oss -i /dev/dsp output.wav
```



balanga said:


> How does ALSA, OSS, Pulseaudio etc fit into the whole picture?


ALSA: Linux changed the whole interface to something a lot more complex because they couldn't get OSS right with "modern" requirements. Don't even start with pulseaudio.

On FreeBSD, you have a nice and simple OSS interface, /dev/dsp will map to your default devices and support software mixing etc. If you think you need a sound daemon, look for something clean and simple like `sndiod`. You definitely don't need it just to record something.


----------



## balanga (Jun 17, 2019)

Zirias said:


> Huh? As simple as
> 
> ```
> ffmpeg -f oss -i /dev/dsp output.wav
> ...



So OSS is already installed in the base OS?...

Running 
	
	



```
ffmpeg -f oss -i /dev/dsp output.wav
```
gave me:-


> [wav @ 0x805e37600] Non-monotonous DTS in output stream 0:0; previous: 688068, current: 687813; changing to 688068. This may result in incorrect timestamps in the output file.
> [wav @ 0x805e37600] Non-monotonous DTS in output stream 0:0; previous: 689613, current: 689358; changing to 689613. This may result in incorrect timestamps in the output file.
> [wav @ 0x805e37600] Non-monotonous DTS in output stream 0:0; previous: 691158, current: 690904; changing to 691158. This may result in incorrect timestamps in the output file.
> [wav @ 0x805e37600] Non-monotonous DTS in output stream 0:0; previous: 692703, current: 692449; changing to 692703. This may result in incorrect timestamps in the output file.
> ...


So it's not quite that simple....

`cat /dev/sndstat` shows:

```
Installed devices:
pcm0: <Realtek ALC269 (Analog 2.0+HP/2.0)> (play/rec)
pcm1: <Realtek ALC269 (Internal Analog Mic)> (rec)
pcm2: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm3: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm4: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm5: <USB audio> (rec) default
No devices installed from userspace.
```

so am not really sure what /dev/dsp refers to.


----------



## balanga (Jun 17, 2019)

Zirias said:


> ALSA: Linux changed the whole interface to something a lot more complex because they couldn't get OSS right with "modern" requirements. Don't even start with pulseaudio.



I've already installed audio/alsa-utils and audio/xfce4-pulseaudio-plugin hoping that might help sort out my problems. Should I delete them?


----------



## zirias@ (Jun 17, 2019)

balanga said:


> So OSS is already installed in the base OS?...


There's nothing that could be "installed" here, OSS is the interface for sound devices on FreeBSD (traditionally on many "unixy" systems), so the kernel implements it. Linux decided to invent a totally different interface that comes with an overly complex userspace library and lots of tools -- FreeBSD didn't.



balanga said:


> So it's not quite that simple....


did you even bother to check your output file? The console output looks pretty normal to me, the command probably worked just fine.



balanga said:


> so am not really sure what /dev/dsp refers to.


As I told you, it uses whatever you configured as default devices. You already have the relevant section of the handbook ...



balanga said:


> I've already installed audio/alsa-utils and audio/xfce4-pulseaudio-plugin hoping that might help sort out my problems. Should I delete them?


Shouldn't matter, but you definitely don't need them. So, yes, maybe better delete them to be sure there are no unexpected effects.


----------



## shkhln (Jun 17, 2019)

balanga said:


> How does ALSA, OSS, Pulseaudio etc fit into the whole picture?



Since both ALSA and PulseAudio on FreeBSD are routed through OSS, if the sound capture doesn't work with OSS you are screwed either way.


----------



## malavon (Jun 17, 2019)

I'd like to chime in. I personally keep all pulseaudio-related ports far away from my system, it messes up things in ways that are hard to debug or predict.
An example of this is that SDL2 will use pulseaudio output by default if the library exists, before trying out OSS. If pulseaudio isn't configured in that case, it means no sound.

So, OSS is always the way to go on FreeBSD unless it's a piece of software that doesn't support OSS. There aren't many of that, in fact I don't have any installed at all.


----------



## balanga (Jun 17, 2019)

Zirias said:


> did you even bother to check your output file? The console output looks pretty normal to me, the command probably worked just fine.



The output file consists of a 80-byte header followed by 4.5MB of binary zeroes.


----------



## zirias@ (Jun 17, 2019)

balanga said:


> The output file consists of a 80-byte header followed by 4.5MB of binary zeroes.


Which means it DID record, just silence. Well, should be straight-forward from here, check whether you picked the correct device as default (like described in the handbook, `hw.snd.default_unit` -- the output you showed earlier suggests your system is configured to record from an USB device), and check your mixer settings (the recording channel might be muted).


----------



## balanga (Jun 17, 2019)

`cat /dev/sndstat`:

```
Installed devices:
pcm0: <Realtek ALC269 (Analog 2.0+HP/2.0)> (play/rec) default
pcm1: <Realtek ALC269 (Internal Analog Mic)> (rec)
pcm2: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm3: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm4: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm5: <USB audio> (rec)
No devices installed from userspace.
```
`sysctl hw.snd.default_unit=5`
`cat /dev/sndstat`:

```
Installed devices:
pcm0: <Realtek ALC269 (Analog 2.0+HP/2.0)> (play/rec)
pcm1: <Realtek ALC269 (Internal Analog Mic)> (rec)
pcm2: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm3: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm4: <Intel Panther Point (HDMI/DP 8ch)> (play)
pcm5: <USB audio> (rec) default
No devices installed from userspace.
```



Zirias said:


> check your mixer settings (the recording channel might be muted).



Not sure how to do that.....`mixer` shows:

```
Mixer vol      is currently set to  75:75
Mixer pcm      is currently set to  75:75
Mixer line     is currently set to  75:75
```


----------



## balanga (Jun 17, 2019)

shkhln said:


> Since both ALSA and PulseAudio on FreeBSD are routed through OSS, if the sound capture doesn't work with OSS you are screwed either way.


https://linuxtv.org/wiki/index.php/Easycap#Empia_EasyCAP 
shows:-





> *Empia EasyCAP*
> The Empia EasyCAP is based on the EM2860 chip from Empia.
> 
> *Components Used*
> ...



I don't see this explicitly supported but the device is recognised and there is no problem capturing Video.

Is there any way to tell if anyone has ever successfully used Audio capture under FreeBSD with this device?


----------



## The_Paya (Jul 29, 2019)

Try with:
`# mixer -f /dev/mixer5 mic 100:100`
Assuming there is one "mic" device in the output of "mixer -f /dev/mixer5"
Then attempt to record:
`# ffmpeg -f oss -i /dev/dsp5 -filter:a "asetpts=N/SR/TB" test.wav`
The audio filter only sets the presentation timestamp of each frame to the frame number, don't expect perfect synchronization (it will still be better than the "Non-monotonous DTS" error)


----------



## 465788227 (Feb 5, 2020)

```
ffmpeg -f oss -i /dev/dsp output.wav
```
 doesn't work!


----------



## shkhln (Feb 5, 2020)

Did you expect it to?


----------



## SirDice (Feb 5, 2020)

Same question, threads merged.


----------



## shkhln (Feb 5, 2020)

I can't honestly tell if that is an appropriate thread for merging, because I don't understand balanga's questions in the first place. As for the non-microphone sound capture (not sure what's the correct term), last time I answered this very question was only two weeks ago. Is the forum search function broken or something?


----------

