Elf – 2WD Pi Robot
Raspberry Pi Camera h.264 Streaming from Elf
Last week, I Elf started streaming from his new Pi Camera using MJPEG.
(Click on image for larger version)
The easy to follow MJPEG-Streamer installation instructions found at Miguel Greenberg’s blog made getting the MJPEG streaming work a piece of cake.
I wish I could say the same for h.264 streaming!
Why did I want to switch to h.264?
I was not happy with the MJPEG frame rate … I found 2-3fps far too choppy for my liking.
After a lot of googling, I tried several methods that seemed promising.
You know the old saying?
Third time is the charm?
It was true once more.
Martin Cazare’s blog posting “Live Streaming Raspberry Pi Camera” worked right away – unlike the other solutions I tried.
Martin’s article also had the virtue of simplicity, with the easiest installation steps of any of the methods I found googling.
- use ‘sudo raspi-config’ to enable the Pi Camera
- use ‘sudo apt-get install vlc’ to install vlc
- execute a single line (shown below) to start streaming!
Here is how Martin’s article streams from the Pi Camera:
raspivid -o - -t 0 -hf -w 800 -h 400 -fps 24 | cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8160}' :demux=h264
This is the simplest, most elegant example I’ve found after a fairly exhaustive search.
Mind you, it would be a lot better if streaming was added to the raspivid utility itself…
Picture Quality and Frame Rate
Streaming was rock solid at 24fps, and the picture quality was excellent.
Of course I could not leave well enough alone, and I tried some other settings:
24fps 1280×720: excellent
24fps 1296×994: excellent (this is a quarter of the full sensor resolution)
24fps 648×472: excellent
Next, I tried some other frame rates:
30fps 1296×994
60fps 1296×994 – no stream
45fps 1296×994 – some macro blocking.
I went back to the great 24fps stream 🙂
The Fly in the Ointment
There is a roughly two second lag between what the camera sees, and when the remote VLC client displays it.
Ouch!
But you know what?
Until there is a solution, I’d rather take the much higher resolution h.264 feed with a 2000msec latency than the lower latency 2-3fps MJPEG stream.
Mind you, now I want to reduce this latency…
CPU Utilization
raspivid seems to use only 2% of CPU time.
vlc chews up 19%-26% of the CPU.
It sure would be nice to have raspivid stream a demultiplexed h.264 stream directly… just think of the potential processor time saving (and reduced latency).
Here is how I ended up streaming:
#!/bin/sh raspivid -o - -t 0 -vf -hf -w 1296 -h 972 -fps 24 | cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8160}' :demux=h264
I saved the above as ‘h264.sh’, and set its execute bit with ‘chmod +x h264.sh’ so I could just type ‘./h264.sh’ instead of the long, complicated command line above.
(note the -vf needed as I mounted my Pi Camera upside down on Elf)
Now I just have to find some way of reducing the latency… any and all suggestions on how to reduce latency are welcome!
Coming soon:
- Compass Module support
- Additional sensors
This page is a live build log of Elf, and how he will grow over time. I hope you enjoy this article!
If you have any questions about Elf, please visit the Elf Forum!
Raspberry Pi Camera Links
- Raspberry Pi Camera documentation
- Raspberry Pi Camera – new modes
- Installing MJPEG-Streamer
- MJPG-streamer on SourceForge
- Setting up a RAM drive on Raspberry Pi
- Live Streaming Rspberry Pi Camera
Article Index
- Meet Elf
- Power supply & Development
- Building Elf: RoboPi, Servos, Sensors, Analog In
- Connecting the Motor Controller & Range Sensor, Sample Code & more
- Adding a Raspberry Pi Camera to Elf
- Installing & Using MJPG-Streamer
- Raspberry Pi Camera h.264 Streaming from Elf
Related links: