Target of this short how-to is to describe a way to set up MJPG with a “special library/plugin” (input_raspicam.so) to grab the stream directly(!) from the RaspberryPi Cam-Modul and immediately forward it as MPJEG towards “motion” as a network camera stream.
It's possible to put pretty high resolutions in, but even with less like 1024px x 768px, there won't be more than max 3fps. Usually this is acceptable to grab some motion on one hand and get a very detailed picture on the other hand, but try it on your own.
I assume motion already to be installed and working. If not yet done, follow one of the other tutorials/how-tos out there.
So first prepare some basic tools:
sudo apt-get install libjpeg62-dev cmake git
Then grab a copy of the git build source (from Tom Stoeveken):
pi@raspberrypi ~ $> git clone https://github.com/jacksonliam/mjpg-streamer.git Klone nach 'mjpg-streamer'... remote: Counting objects: 2004, done. remote: Compressing objects: 100% (831/831), done. remote: Total 2004 (delta 1168), reused 1981 (delta 1148) Empfange Objekte: 100% (2004/2004), 3.29 MiB | 996 KiB/s, done. Löse Unterschiede auf: 100% (1168/1168), done.
If the git should be offline or damaged, you can use a copy taken today (23.10.2013) including a startup-script from Andreas Link. Download mjpg-streamer-raspicam.tar.gz
After that you have to change into the new directory inside the new automatically created folder and build the modul:
cd mjpg-streamer/mjpg-streamer-experimental/ make && sudo make install
When all this is done, it's more or less done .
You can make test by just calling the mjpeg-stream and open the stream in your browser like Chromium. But first remind to export the path to the lib (assuming it to be in /usr/local/lib/ like e.g. /usr/local/lib/input_raspicam.so and /usr/local/lib/output_http.so) or hardcode these paths.
export LD_LIBRARY_PATH="/usr/local/lib" ./mjpg_streamer -i "input_raspicam.so -ex night -x 640 -y 480 -d 0" -o "output_http.so -p 8090 -w www"
Update: Since the last update/git download (01.2014) you can add a “fps” param and therefor increase the stream rate, which is quite impressive (Info: Param “-d” died.). Run the mjpeg_streamer by calling:
export LD_LIBRARY_PATH="/usr/local/lib" ./mjpg_streamer -i "input_raspicam.so -x 640 -y 480 -fps 15 -vs -quality 90" -o "output_http.so -p 8090 -w /usr/local/www"
Get the MJPEG-Stream in your browser, when you call:
(Assuming 192.168.0.206 ist the IP of your raspi.)
Just to mention this, but you could also implement this stream easily inside a website by just integrating it like a picture:
<img src="http://192.168.0.206:8090/?action=stream" border="1" />
When all this is done, you can add this stream in motion by just adding it as a netcam. Therefore just find the row, where the cam can be added:
# URL to use if you are using a network camera, size will be autodetected (incl http:// ftp:// or file:///) netcam_url http://localhost:8090/?action=stream
You don't need any resolutions in motion anymore and you shoud comment the row with the former video device like /dev/video0 (unless you have a multithreaded motion setup).
There are several resolution possible, I was successful with these:
Remind “mjpg_stream” is quite flexible, but “motion” only accepts resolutions which are valid when calculated modulo 16! And also keep in mind, this all is just on alpha stadium, so don't be disappointed, when it might hang after a while or when interrupted.
Just to mention some advantages and disadvantages which come within this solution: