I have four UBS-Webcams, each of the Cameras is used as input for two processes. As the USB-cameras provide only exclusive access to one single process, I used v4l2loopback to map/loopback each camera to two virtual devices. As I know this is standard method (Link)
I created a systemctl service for creating the virtual devices and 4 other services for the loopback. I tried to do the loopback with ffmpeg and gstreamer, but only gstreamer worked for me so far.
The "consumer" processes at the end of the chain that uses the video data is also Gstreamer, everything with the same resolution.
Everything works quite good for a while. But after some time (sometimes some hours, sometime several days) something in one of the four chains is failing and the consumer processes don't get data any more. Then I have to stop and start the loopback services and consumer processes manually, and everything is working fine again.
My question is:
- How can I debug the exact cause of failure that is occuring? (Most probably Gstreamer loopback)
- How can I build some kind of watchdog that is detecting the error and reestablishing the functionality automatically?
The System is Debian on a x86_64.
Service for creating virtual devices:
# loopback-modulload.service
[Unit]
Description=loopback kernel module loading
After=network.target
[Service]
Type=oneshot
RestartSec=2
User=root
WorkingDirectory=/root
ExecStart=/usr/sbin/modprobe v4l2loopback video_nr=10,12,14,16,20,22,24,26 card_label="Virt0-A,Virt0-B,Virt2-A,Virt2-B,Virt4-A,Virt4-B,Virt6-A,Virt6-B" exclusive_caps=1,1,1,1,1,1,1,1 max_buffers=2
[Install]
WantedBy=multi-user.target
One of the four services to do the loopback, (need the virtual devices existing):
[Unit]
Description=l4v2-loopback prozess for usb-cam video0
After=loopback-modulload.service
[Service]
Environment="DEV_PHYS=/dev/video0" "DEV_VIRT_1=/dev/video10" "DEV_VIRT_2=/dev/video20"
Type=exec
Restart=always
RestartSec=2
User=root
WorkingDirectory=/root
# sleep to wait until virtual devices of "loopback kernel module loading" are existing at execution
ExecStartPre=/bin/sleep 3
ExecStart=/usr/bin/gst-launch-1.0 v4l2src device=${DEV_PHYS} ! "image/jpeg,width=960,height=540,framerate=30/1" ! tee name=t ! queue ! v4l2sink device=${DEV_VIRT_1} t. ! queue ! v4l2sink device=${DEV_VIRT_2}
[Install]
WantedBy=multi-user.target
Thanks a lot for every comment or answer!