Wednesday, June 26, 2013

Video/Media Streaming Server( MJPG-Streamer)


Introductions:

Video Streaming is an awesome feature/s that you can add with your own published websites.Because viewing a remotely captured frame of images  in real time is quite exciting configurations in your web server. Well, there are a lot of useful applications that technos can do with this tutorial/s; say, using the said application  as home surveillance or monitoring households,  remote sensing and data gathering with images and videos.The  DIY guide of this blog  would not require enthusiast for an expensive equipment(DVR and CAM grabber)-hence a simple web or IP camera will do the trick.I am  telling  you folks to go to CDR-King and buy for your selves the cheapest camera in town.

Yet personally, my sole aim is to put this web cameras on-board the machine ; from-thence  I want to control stuffs remotely.I am practically concern of a DIY mobile robots.Since I've posted it in our FB PSCoE forum, its my pleasure to bring the set-up into details.It is somewhat a simple expectation and  learning curve for advancement of "hobbying" about "internet of things". Wishing that in the near posts there would be more variety of designs involving online machine vision and image processing.

Perhaps , that could be a great challenge to tackle about setting-up a server that is capable of hosting online videos(live) to its clients.Here in our next techno-article we will explain ideas how this purpose would be achieved with free software available (of course for free) on the net.There are two software programs which have given online video streaming a seamless possibilities to geeks in the open source community.These are motion and mjpg-streamer, both run in the different flavour/distro of Linux/Unix OS.Yet for now,  it will be our desire to use mjpg-streamer then motion will be discussed in the next techno-blog-How about that?

During the testing , we will try to use different viewer/player  to remotely capture the videos ,either WAN or LAN streaming.This will happen using:  Apache2 for web ,VideoLAN for local, and CLI command for shell frame monitoring. So without much further ado, lets try to do it now folks! 



Requirements:
Linux OS: Ubunto/Fedora/CentOS (here I used Ubuntu 12.10v)
Two(2 ) or 3 Web Cameras
CPU  core 2 duo /i7 (PC) or Raspberry PI (embedded)


Methodology:

Downloadable
mjpg-streamer download link
http://sourceforge.net/projects/mjpg-streamer/files/mjpg-streamer/Ubuntu%208.04%20packages/

Installations:
root@localhost# apt-get install subversion libv4l-dev libjpeg8-dev
root@localhost# apt-get install imagemagick fswebcam
root@localhost# apt-get install apache2 php php-devel 

1) You can install and compile mjpg-streamer from the source
root@localhost# svn co https://mjpg-streamer.svn.sourceforge.net/svnroot/mjpg-streamer mjpg-streamer

root@localhost# cd mjpg-streamer/mjpg-streamer
root@localhost# make USE_LIBV4L2=true clean all
root@localhost# sudo make DESTDIR=/usr install
root@localhost# cd ../..
root@localhost# rm -rf mjpg-streamer

2) Installation done using apt-get  and opening it with software application launcher
root@localhost# apt-get install mjpg-streamer

Configurations (for device and ports)

(1)check the available  video camera (web/IP ,etc)
root@localhost# ls -lst /dev/video* 

(2)check if its detected by your pC
root@localhost# lspci  

(3) check if it has  driver /brand in linux
root@localhost # lsusb  

(4) check specs and parameters
root@localhost# dmesg

Testing
1) Test If cameras are streaming
root@localhost# sudo fswebcam --verbose
--- Opening /dev/video0...
Trying source module v4l2...
/dev/video0 opened.

src_v4l2_set_pix_format,541: Device offers the following V4L2 pixel formats:
src_v4l2_set_pix_format,554: 0: [0x56595559] 'YUYV' (YUV 4:2:2 (YUYV))
src_v4l2_set_pix_format,554: 1: [0x47504A4D] 'MJPG' (MJPEG)
Using palette MJPEG


2)  Doing the streaming by assigning input(video file ,device camera,resolution,frame and output(web,localhost,etc)
root@localhost#  mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -f 60 -r 960x720" -o "output_http.so -p 8085 -n"

2) Browse the video streaming over http
2.1) browse it on the web for streaming
http://localhost:8085?action=stream

2.2) browse it on the web for snapshot
http://localhost:8085?action=snapshot

3) Here are the commands to be included in the script/s to stop and start the mjpg-streamer applications
3.1) To start the application
root@localhost#  mjpg_streamer -b -i "/usr/lib/input_uvc.so -d /dev/video0" -o "/usr/lib/output_http.so -p 8085 -w /var/www/mjpg_streamer -n"

3.2) To stop the application
root@localhost# killall mjpg_streamer

3.3) To restart the application
root@localhost# killall mjpg_streamer
root@localhost#  mjpg_streamer -b -i "/usr/lib/input_uvc.so -d /dev/video0" -o "/usr/lib/output_http.so -p 8085 -w /var/www/mjpg_streamer -n"



Details:

1) MJPG-streamer download site




















2) Opening mjpg-streamer in a launcher software application










3)  Typo Error 94.1 version












4)  Corrections for typo error : 94_r1 to 94.1 (version)

















5) localhost with port video streaming














6) Video Lan for video streaming






7) Web video streaming with html script and apache2




















8) HTML  simple web script for publishing two videos


9) Video streaming multi-camera (just two for my spare)





Remarks:

(1)Troubles
The  description of the package version does not comply with the "Center of applications." So  we need to rebuild the package to solve it.

Shooting(a)
1.1) Download the latest build mjpg-streamer_r94-1_i386.deb 
1.2) Renaming it mjpg-streamer.deb 
1.3) Put in the root of your user directory  "tmpdir".
root@localhost# mkdir   tmpdir
root@localhost#  mv  mjpg-streamer_r94-1_i386.deb mjpg-streamer.deb
-->
root@localhost# dpkg-deb -x mjpg-streamer.deb tmpdir
root@localhost# dpkg-deb -control mjpg-streamer.deb tmpdir/DEBIAN

1.4) Now in any text editor change the version number in the file tmpdir/DEBIAN/control with r94-1 at 94.1
root@localhost# nano tmpdir/DEBIAN/control
root@localhost# dpkg -b tmpdir mjpeg-streamer_my.deb

1.5) mjpeg-streamer_my.deb is now ready to install.

Shootin(b)
1.6) Open the file  mjpg-streamer_r94-1_i386.deb and extract it
1.7) Search  and edit  the file "DEBIAN/control
1.8) change the text version DEBIAN/control with r94-1 at 94.1 
1.9) Open it with Ubuntu application launcher


(2) Troubles
input_uvc.so: cannot open shared object file: No such file or directory
 
MJPG Streamer Version.: 2.0
ERROR: could not find input plugin
       Perhaps you want to adjust the search path with:
       # export LD_LIBRARY_PATH=/path/to/plugin/folder
       dlopen: input_uvc.so: cannot open shared object 
        file: No such file or directory

Shooting
2.1) locate "input_uvc.so"
root@localhost# which input_uvc.so
2.2) Install uvc object
root@localhost# sudo apt-get install input_uvc.so
3) Troubles:
Can't display the mjpg-streaming though it streams frame of images
Shooting 
 mjpg_streamer -i "/usr/lib/input_uvc.so -d /dev/video0 -f 60 -r 960x720" -o "output_http.so -p 58180 -n"


Conclusions:
Completed an on-line video/media server, and is now ready to use for a mobile robots