4

How can I record the audio of an application like Firefox inside a docker container with ffmpeg? I've found examples how to forward pulseaudio to the host - netflix, skype.

When I'm trying 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'm getting an error:

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

This also fail

ffmpeg -f pulse -i default /tmp/pulse.wav
pablo
  • 2,719
  • 11
  • 49
  • 67

2 Answers2

2

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

However! I have gotten connection errors if I'm using a pulse audio library that needs X. I used 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 things were playing sound, but this guide seemed a nice detailed coverage of how to use loopback devices to record stuff.

Pang
  • 9,564
  • 146
  • 81
  • 122
user2077221
  • 897
  • 8
  • 11
0

By default you don't have access to the sound card inside the container. If you pass the --privileged flag to docker run, it should work. Note that this will give the container full privileges on the host, you might want to restrict this to a set of capabilities.

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

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102
  • The host is a VPS so it doesn't have a sound card either. I'm interested in recording the audio with a virtual sound card similar to using a virtual frame buffer. – pablo Dec 24 '14 at 15:05
  • Well that changes things. No idea about virtual soundcards, but I still suspect it is a privileges issue. – Adrian Mouat Dec 24 '14 at 15:10
  • This might help http://stackoverflow.com/questions/21688115/pactl-called-from-systemd-service-always-reports-pa-context-connect-failed-co but it looks like you might struggle to do this in Docker. It would make a good blog if you succeed. – Adrian Mouat Dec 24 '14 at 15:13
  • I'm running pulseaudio manually with: "pulseaudio --log-level=debug &" Adding loopback with: "pactl load-module module-null-sink sink_name=mix pactl load-module module-loopback sink=mix" and recording with: "avconv -f pulse -i default /opt/recording /record.wav". It does record something but the sound is broken. – pablo Dec 24 '14 at 15:22