Monday, June 3, 2013

Use #RaspberryPi CSI camera module to stream live video to Bambuser

The new CSI camera module for the raspberry pi make it posible to stream high-definition video without having problem with performance. Streaming with ffmpeg will use about 2-4% and raspivid 1-2% of the CPU.

I am using Adafruit Occidentalis distro that is build on raspbian.
Start by upgrade the Raspberry Pi firmware and install the camera module

sudo apt-get update
sudo apt-get upgrade
sudo raspi-config

Enable the camera

Enable Camera
Enable the camera

More information on how to install the camera module

First ffmpeg need to be removed and install from source. The reason for this is that the package distributed through apt-get is not compiled with H264 suport.
Compiling the code takes a few hours so start it in a screen so it do not stop if losing connection to the pi or do a cross compile.
To use screen

sudo apt-get install screen
Compile and install ffmpeg

sudo apt-get remove ffmpeg
cd /usr/src
sudo mkdir ffmpeg
sudo chown `whoami`:users ffmpeg
git clone git:// ffmpeg
cd ffmpeg
sudo make install

Now it is time to get your stream url and key from Bambuser

raspivid -t 9999999 -w 960 -h 540 -fps 25 -b 500000 -o - | ffmpeg -i - -vcodec copy -an -metadata title="Streaming from raspberry pi camera" -f flv [url]/[id]

If the image need to be flipped or mirrored -hf and -vf can be use on the raspivid command.

-hf, --hflip    : Set horizontal flip
-vf, --vflip    : Set vertical flip

Now you should be able to se the video on your Bambuser dashboard

This will likely be work with other streaming services as ustream and

Happy hacking