4

I'm trying to set up a Docker container with Selenium that takes a recording of the browser with system audio using ffmpeg. I've got video working using Xvfb. Unfortunately, on the audio side, it seems to be more tricky.

I thought I would set up a virtual pulseaudio sink inside the container, which would allow me to record its monitor:

pacmd load-module module-null-sink sink_name=loopback
pacmd set-default-sink loopback
ffmpeg -f pulse -i loopback.monitor test.wav

This works on my host operating system, but when trying to start the pulseaudio daemon in a container, it fails with the following message:

E: [pulseaudio] module-console-kit.c: Unable to contact D-Bus system bus: org.freedesktop.DBus.Error.FileNotFound: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory

This would seem to be related to a freedesktop service called dbus. I've tried installing it and starting its daemon, but I couldn't seem to get it to work properly. I couldn't find much information on how to proceed from here. What am I missing for pulseaudio? Perhaps there's an easier way to record the system audio inside a container?

My goal is not to record it from the host operating system, but to play the audio inside the browser and record it all inside the same container.

XXLuigiMario
  • 125
  • 1
  • 8
  • This sounds like you need more of the standard Linux desktop environment than normally runs inside a Docker container. A full virtual machine (with simulated display and audio hardware) running a normal desktop Linux setup might be a better match for this application. – David Maze Sep 24 '20 at 00:42
  • I'm doing the same thing. But the recoded video has crackles in audio. Did you face this problem, too ? – boygiandi Jan 09 '21 at 08:26
  • @boygiandi I'm facing the same issue, were you able to find a solution? – David Mar 01 '21 at 06:45
  • @David yes. It's because of a looping video in Xvfb. Every time it loop, it make the crackles sound. – boygiandi Mar 01 '21 at 08:06
  • @boygiandi What was the solution you implemented? Any reference/links I can look at? Also I'm not taking a screengrab using xvfb, only audio recording using default device – David Mar 01 '21 at 09:15
  • @boygiandi I’m seeing the same issue when trying to do a screen capture with XVFB - I’m not really sure what you mean by the looping bit but wondering if you could share what worked. – john_ryan Aug 10 '21 at 02:05
  • @David were you able to find a solution? – john_ryan Aug 10 '21 at 02:06

2 Answers2

7

Following solution from here helped me.

Run following commands as root prior to starting PulseAudio:

mkdir -p /var/run/dbus
dbus-uuidgen > /var/lib/dbus/machine-id
dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address
Envek
  • 4,426
  • 3
  • 34
  • 42
  • Thank you, that did it. I also had to comment out `load-module module-console-kit` from `/etc/pulse/default.pa` as it resulted in `E: [pulseaudio] module-console-kit.c: GetSessionsForUnixUser() call failed: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.ConsoleKit was not provided by any .service files` which is suppose is due to missing the consolekit package. pulseaudio seems to work fine without this module. – XXLuigiMario Sep 26 '20 at 23:02
  • Once `module-console-kit` is disabled, pulseaudio will even run without dbus, though it does spit out quite a few (non-fatal) errors. – XXLuigiMario Sep 26 '20 at 23:34
  • Do you folks have a complete Dockerfile or entrypoint available for reference? @XXLuigiMario – slhck Mar 20 '23 at 08:22
  • @slhck mine is here: https://github.com/Envek/dockerized-browser-streamer – Envek Mar 20 '23 at 13:36
  • @Envek Thanks! pacmd never worked for me, weird. I found another solution in the answer I gave below. – slhck Mar 20 '23 at 15:36
0

The accepted answer did not work for me on its own. What was needed was a more complex setup which included deleting some pulseaudio directories. The entire solution can be found here: https://superuser.com/a/1545361/48078

Specifically, it needed:

RUN adduser root pulse-access

And in the entrypoint:

rm -rf /var/run/pulse /var/lib/pulse /root/.config/pulse
pulseaudio -D --verbose --exit-idle-time=-1 --system --disallow-exit
slhck
  • 36,575
  • 28
  • 148
  • 201