No sound on Balena OS with RPI4

Hi,
I’m trying to play mp3 files in docker container on RPI4 board. In the container I use nodejs and MPV to play mp3 files.
Actually I have succeeded it on Raspbian and now it’s time to give it a try on BalenaOS. I use node:14-bullseye as a base image on Rasbian.

Here is my docker-compose file. I mounted the sound device /dev/snd also.

docker-compose.yaml

version: '2.4'

services:
  component:
    build:
      context: .
      dockerfile: Dockerfile_balena

    image: musicplayer
    network_mode: 'host'
    restart: unless-stopped
    devices:
      - "/dev/snd"
    privileged: true
    environment:
      - ENDPT_ADDR=${ENDPT_ADDR}

Dockerfile_balena

FROM balenalib/raspberrypi4-64-debian-node:14-sid

RUN apt update

RUN apt -y install nmap
RUN apt -y install cmake build-essential libssl-dev python3 ssh sshpass
RUN npm install -g --unsafe-perm pm2
RUN pm2 install pm2-logrotate
RUN pm2 set pm2-logrotate:retain 7

RUN mkdir -p /work/dist
WORKDIR /work
RUN mkdir -p /greengrass/v2/
COPY crt/* /greengrass/v2/
COPY lounge-info.json  /greengrass/v2/

RUN apt install -y mpv

COPY package.json /work/
COPY .npmrc /work/
RUN yarn install
COPY component.json /work/

COPY ecosystem.config.js /work/
COPY tsconfig.json /work/
COPY dist /work/dist

CMD pm2-runtime start ecosystem.config.js

When I run this service, I noticed that errors occurred without detailed message.

So I run the mpv in the container with this command mpv --no-video /music/piano1.mp3. Please refer to the logs

root@c2e8aeb:/var/log# mpv --no-video /music/piano1.mp3
[W][02258.304617] pw.conf      | [          conf.c:  939 try_load_conf()] can't load config client.conf: No such file or directory
[E][02258.304684] pw.conf      | [          conf.c:  963 pw_conf_load_conf_for_context()] can't load default config client.conf: No such file or directory
[ao/alsa] Playback open error: No such device
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
[ao/jack] cannot open server
[ao/sdl] could not open audio: ALSA: Couldn't open audio device: No such device
[ao] Failed to initialize audio driver 'sdl'
Could not open/initialize audio device -> no sound.
Audio: no audio

Exiting... (Errors when loading file)

In the /dev/ directory in the container, there are devices like below

root@c2e8aeb:/dev# ls
ashmem         cpu_dma_latency  gpiochip1  kvm           loop6      mmcblk0p4  ptmx   ram14  ram8            rpivid-vp9mem  stdout  tty14  tty21  tty29  tty36  tty43  tty50  tty58  tty8       vc-mem  vcs5   vcsa6  vga_arbiter
autofs         cuse             gpiomem    loop-control  loop7      mmcblk0p5  pts    ram15  ram9            shm            tty     tty15  tty22  tty3   tty37  tty44  tty51  tty59  tty9       vchiq   vcs6   vcsu   vhci
btrfs-control  dma_heap         hwrng      loop0         mapper     mmcblk0p6  ram0   ram2   random          snapshot       tty0    tty16  tty23  tty30  tty38  tty45  tty52  tty6   ttyAMA0    vcio    vcsa   vcsu1  vhost-net
bus            dri              i2c-1      loop1         mem        mqueue     ram1   ram3   raw             snd            tty1    tty17  tty24  tty31  tty39  tty46  tty53  tty60  ttyprintk  vcs     vcsa1  vcsu2  vhost-vsock
cachefiles     fd               i2c-20     loop2         mmcblk0    net        ram10  ram4   rfkill          spidev0.0      tty10   tty18  tty25  tty32  tty4   tty47  tty54  tty61  ubi_ctrl   vcs1    vcsa2  vcsu3  watchdog
cec0           full             i2c-21     loop3         mmcblk0p1  null       ram11  ram5   rpivid-h264mem  spidev0.1      tty11   tty19  tty26  tty33  tty40  tty48  tty55  tty62  uhid       vcs2    vcsa3  vcsu4  watchdog0
cec1           fuse             input      loop4         mmcblk0p2  port       ram12  ram6   rpivid-hevcmem  stderr         tty12   tty2   tty27  tty34  tty41  tty49  tty56  tty63  uinput     vcs3    vcsa4  vcsu5  zero
console        gpiochip0        kmsg       loop5         mmcblk0p3  ppp        ram13  ram7   rpivid-intcmem  stdin          tty13   tty20  tty28  tty35  tty42  tty5   tty57  tty7   urandom    vcs4    vcsa5  vcsu6  zram0

I’m wondering what I am supposed to do.

Please help.

Thank you

Hi @chester ! Welcome to the balena forums – and thanks for this detailed question!

I am not too familiar with MPV, but from the logs it appears that it is trying to use some components that are failing (SDL, Jack, ALSA). First thing that comes to mind is that maybe you need to install some missing package into your image. In particular, maybe some ALSA-related package is missing. (Or maybe SDL – though the MPV folks suggest to use the SDL audio driver only as a last resort, we should probably try ALSA first).

Other than that, there are a couple of things we do to troubleshoot this:

  • Please try adding -v to the command line you when manually run mpv. This will enable verbose output.
  • Try running mpv -ao=help and mpv --audio-device=help. This will help us to identify which drivers and devices are available.
  • You can also try to force a different driver, e.g., mpv -ao=pulse.

I hope this helps! If you need further assistance, please share your new findings when trying the commands suggested above.

Cheers,
Leandro

1 Like

Hi @lmbarros! Thank you for your answer.

I tried to run mpv with options especially audio output. All the audio output devices are failed. It is complaining about ‘Could not open/initialize audio device → no sound.’

So I compared my service with the container on Raspbian(which is based on node:14-bullseye).
To compare, I run aplay -l which lists all soundcards and digital audio devices.

On raspbian

root@raspberrypi:/etc# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7

On balena

root@c2e8aeb:/music# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

There is no headphones on balena. I want to play music through the Headphone, not HDMI. How can I have headphone device on Balena?

Thank you
Chester

Hello @chester, you might want to try removing the “vc4-kms-v3d” DT Overlay in the balenaCloud dashboard Device Configuration. I also suggest looking into the balena Audio Block to route your audio effortlessly: GitHub - balena-labs-projects/audio: Audio building block for balenaOS, based on pulseaudio.
Here’s an example that plays an mp3 to the Pi 4 headphone jack using mpv in a container on balena: GitHub - alanb128/balena-audio-example: Using the balena audio block to route audio among containers

1 Like

Thank you @alanb128 , Only with disabling vc4-kms-v3d, I was able to make it work.

Thank again and Happy new year!