Record local audio in docker container

How do I record the sound of an application like Firefox to a docker container using ffmpeg? I found examples on how to redirect pulseaudio to host - netflix , skype .

When I try to use pactl:

pactl list sources

      

or

docker exec -it <container-id> bash
apt-get install pulseaudio
pactl load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/.pulse-socket

      

I am getting the error:

Connection failure: Connection refused
pa_context_connect() failed: Connection refused

      

This also doesn't work

ffmpeg -f pulse -i default /tmp/pulse.wav

      

+3


source to share


2 answers


You don't need a soundcard in a docker container - pulse sound will create a zero sink / source for you and you can add a loopback device as well if you like.

However! I am having connection errors if I am using an impulse audio library that requires X. I was using Xvfb. And did something like this:



Xvfb :0 -screen 0 1600x1200x24+32 -ac -fbdir /shared_volume&
pulseaudio --start --disallow-exit -vvv --log-target=newfile:"$LOG_DIR/pulseaudio.log" --daemonize&

      

I just needed to detect when something sounds, but this guide seemed like a nice detailed coverage of how to use loopback devices to record material.

+1


source


By default, you don't have access to the soundcard inside the container. If you pass the flag --privileged

to run docker it should work. Note that this will give the container full privileges on the host, you can restrict this to a set of capabilities.



For more information: https://docs.docker.com/reference/run/#runtime-privilege-linux-capabilities-and-lxc-configuration

0


source







All Articles