MPD Dockerfile and Equalizer
Music Player Daemon via Docker including FFmpeg-based equalizer filter plugin without ALSA.
The Music Player Daemon package that most distributions ship is usually quite outdated and thus missing interesting features. Also, the fixed selection of compiled-in modules might not fit the desired use-case, either due to needlessly complicated dependencies or the lack of a certain capability.
Using this Dockerfile to build and run MPD inside a Docker container allows to use the most recent version with up-to-date multimedia libraries and without tainting the host.
The build process has two separate stages, one for compiling with library headers, and one for the resulting binary with library dependencies.
Per default, basically only ffmpeg
input and http
output (via lame
, flac
, opus
, or ogg
) from debian:bookworm-slim
is included.
See the MPD compiling manual and the meson compile options for more details, i.e., on how to enable other features.
docker build --pull -t mpd:local .
docker run --rm --stop-signal=SIGTERM --network=host --security-opt=no-new-privileges:true --cap-drop=all \
-v /home/user/Music:/media:ro -v /etc/mpd.conf:/etc/mpd.conf:ro -v /var/mpd:/run/mpd --read-only \
--user $(id -u mpd):$(getent group audio | cut -d: -f3) --name mpd mpd:local
For configuration, /etc/mpd.conf
is needed inside the container or as mounted volume.
When not running the container with --network=host
, the default port 6600 should be exposed.
Depending on the configured database and library paths, there is also need for their corresponding volumes (then even --read-only
should work).
Also, additional mounts and configuration might be needed to access the host’s sound device, if not running a HTTP stream for example.
MPD Equalizer
MusicPD introduced libavfilter
support with v0.22 in 2020.
If MPD is built with ffmpeg
enabled and the corresponding library package is installed, a wide range of filters become available as plugin.
Amongst others, multiple equalizer implementations can then be used “natively” from within the MPD configuration file:
filter {
plugin "ffmpeg"
name "eq"
# https://ffmpeg.org/ffmpeg-filters.html#asubboost
#graph "asubboost"
# https://ffmpeg.org/ffmpeg-filters.html#anequalizer
graph "anequalizer=c0 f=32 w=100 g=4 t=0|c1 f=32 w=100 g=4 t=0|c0 f=1500 w=5000 g=-3 t=0|c1 f=1500 w=5000 g=-3 t=0|c0 f=20000 w=18000 g=3 t=0|c1 f=20000 w=18000 g=3 t=0"
}
audio_output {
# …
filters "eq"
}
The main advantage is that this “built-in” approach does not require involving an ALSA equalizer and thus also directly applies to other outputs methods such as HTTP streams.
Parametric EQ Visualization
The above example adds a fully parametric equalizer for three stereo bands:
- 32Hz, 100Hz width, 4dB gain
- 1500Hz, 5000Hz width, -3dB gain
- 20kHz, 18kHz width, 3dB gain
The corresponding curve can be visualized for example by this DSP preset generator app with:
peq 32Hz q0.32 4dB
peq 1500Hz q0.3 -3dB
peq 20kHz q1.11 3dB
Note that the relation between bandwidth w at a certain center frequency f and quality factor q can roughly be expressed as: