"I'm not proud of being a congenital pain in the ass. But I will take money for it."

Streaming video from a Raspberry Pi 4

Mon 19 February 2024 | -- (permalink)

For Reasons, I got interested in using a Raspberry Pi as a video streaming source (think small relatively inexpensive box that can be left on a mantle during a banquet to stream video for guests unable to attend in person). Unsurprisingly, this turns out to be a deep rabbit hole, but the basic tech does seem to work.

Basic kit:

The basic recipe I was (sort of) following was https://opensource.com/article/19/1/basic-live-video-streaming-server. I didn't get as far as setting up nginx on a server, not because it's particularly difficult but because I was mostly interested in finding out whether a Pi4 can keep up with the capture load.

For real use on a headless Pi, OBS-studio may be the wrong tool, there's probably some way to do the same thing with the ffmpeg command line tool, but, again, the main point for today was finding out whether the Pi can keep up with the load at all.

Short answer: yes, it can. It's not professional quality video, but then I wasn't expecting that, the point was what can we do with cheap hardware.

A few notes on things I had to do to get this working:

  1. This was the first time I made serious use of the WiFi on a Pi running Debian (as opposed to LibrElec, HiFiBerryOS, Raspian, ...). It does work, but for some reason ifupdown falls on its face if one tries to configure both IPv4 and IPv6 on the WiFi interface. This appears to be due to ifupdown deciding that each protocol needs its own copy of wpasupplicant, which of course doesn't work. There are various ways of working around this, but one of the simplest turns out to be simply replacing ifupdown with ifupdown2, which reads the same /etc/network/interface* files but manages to bring up both protocols without tripping over its own socks.

    If you don't care about working dual-stack, you can probably ignore this. If you're going to be driving the Pi via a GUI, you'll probably want to use NetworkManager anyway.

  2. The Debian Pi images ship in a minimal server configuration. If you want a desktop environment (eg, for running obs), the simple way is running tasksel install gnome-desktop (or whichever desktop environment you prefer). At least some of the desktop environments behave strangely when run as root, so you'll probably want to create a non-root user (eg, via adduser) before trying to log in via the GUI.

    Presumably this would not be necessary if using some headless ffmpeg incantation (the tricky part would be working out that incantation...).

  3. Out of the box, obs fails to run on the Pi. There's a lot of bad advice on this out there, but buried in all that I found an answer that worked: set the environment variable

    MESA_GL_VERSION_OVERRIDE=3.3
    

    before running obs.

  4. There's an obs-cli command line tool for OBS Studio, but I don't (yet) understand OBS Studio well enough to have done anything useful with this. Might be useful as a fallback, or as a way of remote-controlling OBS via an ssh connection while running the GUI under Xvnc

There's also a separate question of whether RTMP is really the right format to be using. It's widely supported, and it's probably a good solution for getting the stream off of the Pi and onto a server. For distribution it might be better to use WebRTC, but that conversion, if needed, can happen on the server. I haven't dug deeply into this, but SRS looks promising.