User avatar
Ram.Sh
Posts: 205
Joined: Wed Oct 26, 2016 9:14 pm

[SOLVED] Help: ffmpeg and alsa - work as script not as systemd service problem

Mon Jun 29, 2020 4:36 pm

Hello all,

I have a working python code for running ffmpeg to capture video and audio from an HDMI capture, the code works as it should without any problem, however when I try to run the same script using systemd service i get an alsa error:

Code: Select all

[alsa @ 0x1b5f110] cannot open audio device default (No such file or directory)
the above indicates the ffmpeg can't locate the "-f alsa -i default" part although when it runs not as a systemd all is well and the audio captured.

i use the latest OS:

Code: Select all

Linux raspberrypi 4.19.118-v7l+ #1311 SMP Mon Apr 27 14:26:42 BST 2020 armv7l GNU/Linux
my audio inputs are:

Code: Select all

arecord -L
default
    Playback/recording through the PulseAudio sound server
null
    Discard all samples (playback) or generate zero samples (capture)
jack
    JACK Audio Connection Kit
pulse
    PulseAudio Sound Server
usbstream:CARD=b1
    bcm2835 HDMI 1
    USB Stream Output
usbstream:CARD=Headphones
    bcm2835 Headphones
    USB Stream Output
sysdefault:CARD=Link
    Cam Link, USB Audio
    Default Audio Device
front:CARD=Link,DEV=0
    Cam Link, USB Audio
    Front speakers
surround21:CARD=Link,DEV=0
    Cam Link, USB Audio
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Link,DEV=0
    Cam Link, USB Audio
    4.0 Surround output to Front and Rear speakers
surround41:CARD=Link,DEV=0
    Cam Link, USB Audio
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Link,DEV=0
    Cam Link, USB Audio
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Link,DEV=0
    Cam Link, USB Audio
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Link,DEV=0
    Cam Link, USB Audio
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Link,DEV=0
    Cam Link, USB Audio
    IEC958 (S/PDIF) Digital Audio Output
dmix:CARD=Link,DEV=0
    Cam Link, USB Audio
    Direct sample mixing device
dsnoop:CARD=Link,DEV=0
    Cam Link, USB Audio
    Direct sample snooping device
hw:CARD=Link,DEV=0
    Cam Link, USB Audio
    Direct hardware device without any conversions
plughw:CARD=Link,DEV=0
    Cam Link, USB Audio
    Hardware device with all software conversions
usbstream:CARD=Link
    Cam Link
    USB Stream Output
and my current systemd service file is:

Code: Select all

[Unit]
Description=Test

[Service]
Environment=XDG_RUNTIME_DIR=/run/user/1000
Type=simple
User=pi
WorkingDirectory=/home/pi/Desktop/main/StartUp
ExecStartPre=/bin/sleep 10
ExecStart=/usr/bin/python3 /home/pi/Desktop/main/StartUp/Test.py
Restart=always

[Install]
WantedBy=multi-user.target
any help will be highly appreciated as this used to work flawlessly and I had to reformat the PI and I can't make it work again...

Many thanks in advance!!!
Last edited by Ram.Sh on Mon Jun 29, 2020 5:46 pm, edited 1 time in total.

User avatar
Ram.Sh
Posts: 205
Joined: Wed Oct 26, 2016 9:14 pm

Re: Help: ffmpeg and alsa - work as script not as systemd service problem

Mon Jun 29, 2020 5:46 pm

i found the solution, ran this to find out my desired card number:

Code: Select all

cat /proc/asound/cards
0 [b1             ]: bcm2835_hdmi - bcm2835 HDMI 1
                      bcm2835 HDMI 1
 1 [Headphones     ]: bcm2835_headphonbcm2835 Headphones - bcm2835 Headphones
                      bcm2835 Headphones
 2 [Link           ]: USB-Audio - Cam Link
                      Elgato Systems Cam Link at usb-0000:01:00.0-1, super speed
then I created a file:

Code: Select all

sudo nano /etc/asound.conf
with the following default settings:

Code: Select all

defaults.pcm.card 2
defaults.ctl.card 2
now the ffmpeg finds the default audio input when runs as service, unfortunately for me, the video output is not good but that's for a different post.

thank you for listening.

Return to “Troubleshooting”