There are two steps to connecting to the Pulse Audio server:
Server path. By default, the PulseAudio server makes itself accessible to clients by creating a UNIX socket under $XDG_RUNTIME_DIR
. Running commands via sudo
will reset the environment, thus making PulseAudio clients unable to find the server to connect to.
Authentication. By default, the PulseAudio server creates an authentication cookie in ~/.pulse-cookie
, which clients must relay to the server upon connecting. If $HOME
or $PULSE_COOKIE
are not set to the cookie's location, clients will be unable to authenticate.
The complete command of thus running ffmpeg via sudo is as follows:
sudo env \
PULSE_COOKIE=$HOME/.pulse-cookie \
PULSE_SERVER=$XDG_RUNTIME_DIR/pulse/native \
ffmpeg -y -f pulse -i default -acodec aac foo.aac
You can probably substitute PULSE_SERVER
with the -server
ffmpeg device option.