Hi All,
I am enjoying using Balena, great platform and product. I am currently having a problem with a project I am working on. I am wanting to stream/broadcast a video source from a USB capture card to a program like VLC and later other devices. I have a multicontainer project with a few services. I started with the RaspberryPi Surveillance project (using a Pi4b), did some package modifications, and pulled v4l2rtspserver from MASTER and got it working. From there I built out the project with the other containers, and it was all good. But in the last 2 weeks I started to get the following errors. For all my reading I cannot get it working anymore:
10.11.20 09:24:59 (+0100) streaming [INFO] Start RTSP server with -F 25 -W 1920 -H 1080 -P 8555 /dev/video0
10.11.20 09:24:59 (+0100) streaming 2020-11-10 08:24:59,124 [INFO ] - /app/v4l2rtspserver/v4l2wrapper/inc/logger.h:44
10.11.20 09:24:59 (+0100) streaming level:INFO
10.11.20 09:24:59 (+0100) streaming 2020-11-10 08:24:59,126 [NOTICE] - /app/v4l2rtspserver/main.cpp:385
10.11.20 09:24:59 (+0100) streaming Version: 0.2.1-1-gb3e4c03 live555 version:2020.11.05
10.11.20 09:24:59 (+0100) streaming 2020-11-10 08:24:59,131 [NOTICE] - /app/v4l2rtspserver/main.cpp:426
10.11.20 09:24:59 (+0100) streaming Create V4L2 Source.../dev/video0
10.11.20 09:24:59 (+0100) streaming 2020-11-10 08:24:59,133 [NOTICE] - /app/v4l2rtspserver/v4l2wrapper/src/V4l2MmapDevice.cpp:49
10.11.20 09:24:59 (+0100) streaming Device /dev/video0
10.11.20 09:24:59 (+0100) streaming VIDIOC_REQBUFS: Inappropriate ioctl for device
10.11.20 09:24:59 (+0100) streaming 2020-11-10 08:24:59,135 [NOTICE] - /app/v4l2rtspserver/v4l2wrapper/src/V4l2MmapDevice.cpp:141
10.11.20 09:24:59 (+0100) streaming Device /dev/video0
10.11.20 09:24:59 (+0100) streaming VIDIOC_STREAMOFF: Inappropriate ioctl for device
10.1
I also see problems with v4l2-ctl command in the run file not working, but I think that is due to not being able to get a video input now. Is there a way to run the v4l2 commands in the host to check the video settings?
Here is my OS video data by running this command ls /dev | grep video
root@25508ea:~# ls /dev | grep video
video0
video1
video10
video11
video12
video13
video14
video15
video16
Here is my Docker file, Docker-compose, and run file for reference.
Docker-compose:
version: "2.1"
services:
streaming:
build: ./Streaming
environment:
- UDEV=1
privileged: true
ports:
- "8555:8555"
labels:
io.balena.features.dbus: '1'
wifi-repeater:
build: ./wifi
privileged: true
labels:
io.balena.features.dbus: '1'
Dockerfile.template:
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch
# Install deps
RUN apt-get update
RUN apt-get install -y apt-utils build-essential git gcc g++ cmake make liblog4cpp5-dev libv4l-dev liblivemedia-dev v4l-utils net-tools
RUN rm -rf /var/lib/apt/lists/*
# Install v4l2rtspserver
RUN git clone https://github.com/mpromonet/v4l2rtspserver.git /app/v4l2rtspserver \
&& ( cd /app/v4l2rtspserver && cmake . && make && make install)
# Source files
COPY ./src/ /app/
# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1
# Run command
CMD /bin/bash /app/run.sh
Run.sh
#!/bin/bash
set -e
V4L2_KMOD="bcm2835-v4l2"
# Configurable parameters
CAMERA_ROTATE=${CAMERA_ROTATE:-0}
RTSP_PORT=${RTSP_PORT:-8555}
FRAMERATE=${FRAMERATE:-25}
V4L2_W=${V4L2_W:-1920}
V4L2_H=${V4L2_H:-1080}
VIDEO_INPUT=${VIDEO_INPUT:-/dev/video0}
# Get the absolute script location
pushd `dirname $0` > /dev/null 2>&1
SCRIPTPATH=`pwd`
popd > /dev/null 2>&1
. $SCRIPTPATH/helpers.sh
if modprobe -n --first-time $V4L2_KMOD &> /dev/null; then
log "Load kernel module $V4L2_KMOD..."
modprobe $V4L2_KMOD
else
log "Kernel module $V4L2_KMOD already loaded..."
fi
log "Video set to $VIDEO_INPUT..."
log "Rotate to $CAMERA_ROTATE..."
v4l2-ctl --device $VIDEO_INPUT --set-ctrl rotate="$CAMERA_ROTATE"
log "Rotated"
# Did the last run left hanging sockets?
if [ -z "$TIME_WAIT_INTERVAL" ]; then
if [ -f "/proc/sys/net/ipv4/tcp_fin_timeout" ]; then
TIME_WAIT_INTERVAL=$(cat /proc/sys/net/ipv4/tcp_fin_timeout)
else
TIME_WAIT_INTERVAL=60
fi
fi
STARTTIME=$(date +%s)
ENDTIME=$(date +%s)
until [ -z "$(netstat | grep $RTSP_PORT | grep TIME_WAIT)" ]; do
if [ $(($ENDTIME - $STARTTIME)) -le $TIME_WAIT_INTERVAL ]; then
log WARN "Socket is in TIME_WAIT... Waiting..."
sleep 5
ENDTIME=$(date +%s)
else
log ERROR "Socket didn't get out of TIME_WAIT even after $TIME_WAIT_INTERVAL seconds. Bailing out."
exit 1
fi
done
log "Start RTSP server with -F $FRAMERATE -W $V4L2_W -H $V4L2_H -P $RTSP_PORT $VIDEO_INPUT"
/app/v4l2rtspserver/v4l2rtspserver -v -F $FRAMERATE -W $V4L2_W -H $V4L2_H -P $RTSP_PORT $VIDEO_INPUT
So, after this I tried to get VLC working as an alternative. But I get the same/similar errors. So it could be do to with the drivers (which is weird as it was working??)
Docker-compose:
version: "2.1"
# to get the video input use this command in the host OS: ls /dev | grep video
services:
Streamer2:
build: ./Streamer2
privileged: true
ports:
- "8090:8090"
labels:
io.balena.features.dbus: '1'
wifi-repeater:
build: ./wifi
privileged: true
labels:
io.balena.features.dbus: '1'
Dockerfile.template:
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:stretch
# Install dependencies
RUN apt-get update
RUN apt-get install build-essential vlc v4l-utils liblog4cpp5-dev libv4l-dev liblivemedia-dev
WORKDIR /usr/src/app
# This will copy all files in our root to the working directory in the container
COPY . ./
# Enable udevd so that plugged dynamic hardware devices show up in our container.
ENV UDEV=1
# Run command
CMD /bin/bash /usr/src/app/start.sh
Start.sh
#!/bin/bash
VIDEO_INPUT=${VIDEO_INPUT:=0}
RTSP_PORT=${RTSP_PORT:=8090}
# Allow VLC to run as root
sed -i 's/geteuid/getppid/' /usr/bin/vlc
echo "Starting up on port $RTSP_PORT"
cvlc -v v4l2:///dev/video$VIDEO_INPUT --sout '#transcode{vcodec=h264,vb=800,acodec=none}:rtp{sdp=rtsp://:$RTSP_PORT/}'
But I still get the following errors.
10.11.20 10:10:13 (+0100) Starting up on port 8090
10.11.20 10:10:13 (+0100) VLC media player 3.0.11 Vetinari (revision 3.0.11-0-gdc0c5ced72)
10.11.20 10:10:13 (+0100) [0000005562b0c610] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
10.11.20 10:10:13 (+0100) [0000005562b86570] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
10.11.20 10:10:13 (+0100) [0000005562b86570] main interface error: no suitable interface module
10.11.20 10:10:13 (+0100) [0000005562a7e8f0] main libvlc error: interface "dbus,none" initialization failed
10.11.20 10:10:13 (+0100) [0000005562b3da40] main interface error: no suitable interface module
10.11.20 10:10:13 (+0100) [0000005562a7e8f0] main libvlc error: interface "globalhotkeys,none" initialization failed
10.11.20 10:10:13 (+0100) [0000005562b3da40] dummy interface: using the dummy interface module...
10.11.20 10:10:13 (+0100) Failed to query video capabilities: Inappropriate ioctl for device
10.11.20 10:10:13 (+0100) libv4l2: error getting capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) [0000007f94005bc0] v4l2 demux warning: cannot initialize user-space library: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) [0000007f94005bc0] v4l2 demux error: cannot get device capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) Failed to query video capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) libv4l2: error getting capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) [0000007f94005bc0] v4l2 demux warning: cannot initialize user-space library: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) [0000007f94005bc0] v4l2 demux error: cannot get device capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) Failed to query video capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) libv4l2: error getting capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) [0000007f94008ec0] v4l2 stream warning: cannot initialize user-space library: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) [0000007f94008ec0] v4l2 stream error: cannot get device capabilities: Inappropriate ioctl for device
10.11.20 10:10:14 (+0100) [0000007f9c0009f0] main input error: Your input can't be opened
10.11.20 10:10:14 (+0100) [0000007f9c0009f0] main input error: VLC is unable to open the MRL 'v4l2:///dev/video0'. Check the log for details
Sorry of the long post, does anyone have an idea on how to fix or what could have caused this?