Raspberry Pi Camera Module and Streaming

wpsuperadmin raspberry pi, Tutorials Leave a Comment

Now that the camera is connected it’s time to test it. I have always liked setting up a camera for real-time streaming, plus it’s helpful whenever I am away on a trip. With the PIR project, I could use that to record on motion instead of using image based motion. This would allow for no false positives, unless of course you have animals.

You can use the standard mjpg-streamer but it can’t read from the camera module directly and therefore you need to save a file and then read it back. This would be a fast way to wear out your your SD card. I knew there had to be a better solution. Then low and behold I found this:

https://github.com/jacksonliam/mjpg-streamer

He wrote a module that allows you to stream directly from the camera module. It’s not the fastest but it works.

From your home directory:

git clone https://github.com/jacksonliam/mjpg-streamer

$ cd mjpg-streamer/mjpg-experimental

$ make clean all

To launch

$ export LD_LIBRARY_PATH=.
$ ./mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"

Connect via your browser

http://RPi_IP:8080/

I created a mjpg.sh file in my home directory that contains the above and then made it executable:

$ nano mjpg.sh

#!/bin/bash
cd ~/mjpg-streamer/mjpg-streamer-experimental
export LD_LIBRARY_PATH=.
./mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"

$ chmod +x ./mjpg.sh

You could also add this to crontab to have it start with the system.

$ crontab -e

then add

@reboot ~/mjpg.sh

You can use VLC as a streaming client but there is a much greater delay due to buffering. This might be adjustable, I just haven’t checked yet.

Leave a Reply