Sunday, April 5, 2015

Raspbian - Pi Camera - MJPG-Streamer and Raspistill

Raspbian v2015-02-16
MJPG-Streamer v182
Raspistill


Status:

  • 20150505 - Its working. 
Notes:
  • Since pi camera is 5Mpx and HD, we're using 854x480 resolution.
  • Pi camera works at 1~2fps.
  • Using "Sport" exposure option to reduce distortion generated by the moviment.
  • Using 50% for jpeg quality (file size = +- 200kb. If use 10% then +-23Kb, else if 34% then +-150kb, else if 75% then +-240kb, else if  1280x720x50% than +-510kb).
  • With this configuration, CPU use is about  2%~3% for raspistill and +-2% for mjpg-streamer.
  • Using 640x360x50% results in 100kb file size.
  • It works with firefox and chrome (Windows and Android versions).

ToDo:

  • Compare performances (mjpg-streamer-raspistill / motion).

Installing:

  • Enabling Pi Camera:
  • sudo raspi-config
  • Select Enable camera and hit Enter, then go to Finish and you'll be prompted to reboot.
  • Install build dependencies:
  • sudo apt-get install libjpeg8-dev imagemagick libv4l-dev
  • Add missing videodev.h:
  • sudo ln -s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h
  • Download MJPG-Streamer:
  • wget http://sourceforge.net/code-snapshots/svn/m/mj/mjpg-streamer/code/mjpg-streamer-code-182.zip
  • Unzip the MJPG-Streamer source code:
  • unzip mjpg-streamer-code-182.zip
  • Build MJPG-Streamer:
  • cd mjpg-streamer-code-182/mjpg-streamer
  • make mjpg_streamer input_file.so output_http.so
  • Install MJPG-Streamer:
  • sudo cp mjpg_streamer /usr/local/bin
  • sudo cp output_http.so input_file.so /usr/local/lib/
  • sudo cp -R www /usr/local/www
  • Start the camera and MJPG-Streamer:
  • mkdir /tmp/stream
  • raspistill --nopreview -w 640 -h 480 -q 5 -o /tmp/stream/pic.jpg -tl 100 -t 9999999 -th 0:0:0 & LD_LIBRARY_PATH=/usr/local/lib mjpg_streamer -i "input_file.so -f /tmp/stream -n pic.jpg" -o "output_http.so -w /usr/local/www"
  • Cleanup (removing source code files):
  • cd ../../
  • rm -rf mjpg-streamer-182

Testing:

  • http://<Raspberry-pi_IP-address>:8080

References:

Other options for Streaming:
If you like this content, feel free to