Thursday, July 14, 2016

Live streaming video from the Raspberry Pi with Camera v2

Just got my Raspberry Pi Camera v2, cannot wait to unbox and play with it.


I didn't get a good case to fit in the camera module, but it works.  :)


First of all you can start by taking a picture to make sure your camera is working fine:

raspistill -o image.jpg

To capture your first video, you can use the command raspivid:

raspivid -o video.h264

The video is in raw h.264 format.  It is fine to be played back by my omxplayer on the Raspberry, however if you want most of the other video players to play it, it will be better to convert the file into mp4.

sudo apt-get install gpac
MP4Box -fps 30 -add video.h264 video.mp4

For some application such as "motion", the motion detection and video streaming applications, it needs to recognised the video device as /dev/video0.  It is not the case by default for the Pi Camera.

To enable that, you need to run:

sudo modprobe bcm2835-v4l2

You can also put this command in /etc/rc.local so that the next reboot it will run automatically.

Motion is an open source motion detection and surveillance software which can help you to convert your Raspberry Pi into a home surveillance camera.  To start with, you can get the motion package:

sudo apt-get install motion

A few parameters under motion.conf that you can change, such as:

daemon on

which makes the motion run in background when you start the motion server.

You can also change the resolution in the conf file:
width 1280
height 720

change the following parameter to off so that you can access from host other than localhost:
stream_localhost off
webcontrol_localhost off

You can now access the stream via http::8081


And you will get a bunch of files in your home directory, make sure you have enough storage, if not probably you might need to do it off box to a NAS or whatever it is.  These files are created when motion is detected.



These are the links that I've used to aid my setup, listing all here for your reference:
http://www.instructables.com/id/Raspberry-Pi-as-low-cost-HD-surveillance-camera/?ALLSTEPS
http://www.makeuseof.com/tag/raspberry-pi-camera-module/
http://www.raspberrypi-spy.co.uk/2013/05/capturing-hd-video-with-the-pi-camera-module/

No comments: