Carrots and Sticks — A VideoLAN Project

A quick project to help spur creativity, self assessment and productivity- I found myself in need of a throwy camera, something I can place anywhere, and it will still stream video to my main machine.

Considering I'm knee deep in Raspberry Pi 3's, a bitchin webcam that has been sitting unused, and a UPS for the RPI I never set up, I figured it looked like a good combo.

Challengingly enough, getting video streaming out of an RPi3 is not easy nor well documented. Or if it is, I managed to find none of the prior art on the subject.

The first step I took in this direction was to find a great how-to guide which was up at the time of posting here, and props to Steven Gordon for putting it together. However, there were a couple of points that didn't work out of the box, but I liked it because it showed some command of the cvlc interface (rather than try to do this through the GUI), and it looked like a simple server-client setup that I wanted.

For starters, I set up another RPI with Raspbian, setting up the root device on a thumb drive and only leaving the boot partition on the sd card. Those damn SD cards are too finicky, even the class 10 ones, and I've not had trouble with corruption since I started doing this. I put together a repo for automating the process here, which goes over the theory behind the setup a bit more in depth.

However, installing VLC on the RPI and running cvlc as a server immediately was a failure:

# original command attemp cvlc -vvv v4l2:///dev/video0 --sout '#transcode{vcodec=mp2v,acodec=none}:rtp{sdp=rtsp://:8554/}'

The problem with this was two fold:

  • cvlc cli options are some dialect of greek
  • The "mp2v" codec throws errors

Looking into the error details, the MPEG2 codec, specified on the command line as mp2v, seems to not play nicely with the real time transfer (rtp) module.

The problem with vlc docs is that the subject is pretty beefy, so the docs get thick, fast. The biggest help was simply getting a clear description of two things, one being the command line string structure, and the other was the full guide to streaming modules and options. Once I had an idea of how those two work together, I could take all the crap settings I found in other one off blog posts that have gone out of date (like this most certainly has by the time you're reading it), and reverse engineer whatever the hell they were trying to do into something useful for myself.

Armed with a little more knowledge, I found that mp2v can be replaced by mp4v, and that was enough to get a server and client working successfully:

# transcode options transcode{vcodec=mp4v,vb=80,acodec=none,fps=30} # client, untouched: vlc -vvv --network-caching 200 rtsp://192.168.1.206:8554/
This was super stuttery, and had a ton of graphical issues, but was cleary a POC that at least the concept would work.
I finally landed on these settings for the server, dropping the final resolution way, way down:

# transcode options transcode{vcodec=mp4v,acodec=none,fps=25,scale=0.333,threads=3}

Even still the actual framerate is nothing near the requested 25, but it's good enough a stream over the wifi that I could be using it for any variety of ML tests.

← All writing