Hello balena gurus,
I’m working out a Twitch stream that could use a couple of cameras, one for me and one for a robot co-host (which is also being built on balena). It’s a bit silly for sure, yet is helping in getting more comfortable on camera, good for my work (and it’s fun!).
Challenge:
Webcams are really expensive right now.
Opportunity:
I have a couple of Pis with camera modules that are collecting dust. Note: I’m recording audio separately, just focusing on video.
I’ve made some progress so far. balenaCam was a great start, streaming video, accessible via a web page that I could view in the browser. Browser sources can be included as a layer in an OBS (Open Broadcaster Software) video streams and I could see decent quality images coming in from balenaCam. Cool!
balenaCam hasn’t been the best for a live stream use case though as there’s about a one second delay to see it in a browser on the same wired network (viewing over ethernet on same switch). Much was learned from it though and I see it for other uses.
rpisurveillance in the balena playground was great to look at. It streams to its own RTSP server that can be accessed via VLC Player on the PC. I liked that the frame rate was higher and less compressed, using the Pi’s video encoding capabilities as part of that. As OBS has VLC Player built-in for layer use, I was also able to include it efficiently there.
Challenge with this is that it still had roughly 700ms-ish to one second of latency. I could use this in a pinch for sure as it’s possible to delay audio to match video. It just hits a social awkward point in a stream with that extra second, kind of like you would see with live news coverage on the other side of the world. Not the best for a Twitch stream where there’s timely action happening. Maybe there are settings that can be tweaked to reduce latency (tried everything in VLC Player)? Frame rate and dimensions don’t seem to make a noticeable difference on the Pi side so far.
Then I cam across a service called alohacam. They claim “Zero latency (well, almost)”. I set up an account and took a look at their install code. I haven’t moved too far down this road as I didn’t really want another 3rd party in the mix and the browser viewer didn’t quite work for stream needs. It seems like an earlier stage experiment for a company (nice site design in general though). It also would need some work to get it to work in balena where I want to deploy and monitor.
One last idea: I read that you could pipe raspivid output to an internal RTSP stream with one line of code (hah will expand for sure):
raspivid -o - -t 0 -n | cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
That’s cool and could be something to try. However, when I do, I get vlc errors on the Pi as VLC really doesn’t want to run as root. I’ll need to figure out how to build from source with the --enable-run-as-root
flag in the Docker build to try it out. Otherwise/and, I get errors when running with bless:
raspivid -o - -t 0 -n | bless cvlc -vvv stream:///dev/stdin --sout '#rtp{sdp=rtsp://:8554/}' :demux=h264
Error recalling from bad memory: Not able to to connect to a likely undefined display (more setup likely with x server on headless Pi?
Here’s a starting point to play with:
FROM balenalib/%%BALENA_MACHINE_NAME%%-node
# Install dependencies
RUN install_packages build-essential libraspberrypi-bin vlc bless
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
# server.js will run when container starts up on the device
CMD ["/bin/bash", "/usr/src/app/start.sh"]
Also, maybe I could make a Pi Zero a webcam?? This makes me think it could* be possible. However I have no idea on where to start there:
At the moment I need to give it a short break and document somewhere. How about here?
Any thoughts on this? Have I reached max potential or do you have ideas on how to make a less-latency video stream from a Pi? Thanks for taking a look in advance!