Sunday, 26 August 2012 17:49

TP-LINK TL-WR1043ND Router + Web Cam = IP Cam

This is an article to guide you on how to use a webcam attach to a router and act as an IP camera. At the end of the article, it show you how to adding authentication to the project.
 
 Prerequisites
 
 
Microsoft LifeCam HD-5000
You should purchase webcam with Linux UVC support. Read here for more about Linux UVC driver and tool. 
From the Linux UVC website, you should see a list of supported camera. Purchase camera with green sign as shown in figure below.

 Linux UVC Webcam

Installation
SSH to router and install packages as shown below.
opkg update
opkg install kmod-usb2
opkg install kmod-video-uvc
opkg install kmod-i2c-core
opkg install kmod-input-core
opkg install mjpg-streamer
 
 
Settings for Video
If you want to change video resolution, frame per second, or port, edit /etc/config/mjpg-streamer as shown in below. Reboot the router after save settings.

config mjpg-streamer core
option device "/dev/video0"
option resolution "640x480"
option fps "5"
option port "8080"
option enabled "true"

 
For Microsoft LifeCam HD-5000 web cam, the resolution can go up to 1280x720. Wow! what a high resolution web cam.
option resolution "1280x720"
 
 
Startup on Router Power On
/etc/init.d/mjpg-streamer enable
 
 
Some Information about mjpg_streamer
Below is some pictures showing you how to use mjpg_streamer. Just SSH to router and enter mjpg_streamer --help
[email protected]:~# mjpg_streamer --help
-----------------------------------------------------------------------
Usage: mjpg_streamer
-i | --input "<input-plugin.so> [parameters]"
-o | --output "<output-plugin.so> [parameters]"
[-h | --help ]........: display this help
[-v | --version ].....: display version information
[-b | --background]...: fork to the background, daemon mode
-----------------------------------------------------------------------
Example #1:
To open an UVC webcam "/dev/video1" and stream it via HTTP:
mjpg_streamer -i "input_uvc.so -d /dev/video1" -o "output_http.so"
-----------------------------------------------------------------------
Example #2:
To open an UVC webcam and stream via HTTP port 8090:
mjpg_streamer -i "input_uvc.so" -o "output_http.so -p 8090"
-----------------------------------------------------------------------
Example #3:
To get help for a certain input plugin:
mjpg_streamer -i "input_uvc.so --help"
-----------------------------------------------------------------------
In case the modules (=plugins) can not be found:
* Set the default search path for the modules with:
export LD_LIBRARY_PATH=/path/to/plugins,
* or put the plugins into the "/lib/" or "/usr/lib" folder,
* or instead of just providing the plugin file name, use a complete
path and filename:
mjpg_streamer -i "/path/to/modules/input_uvc.so"
Help for input_unv.so plugin:

[email protected]:~# mjpg_streamer --input "input_uvc.so --help"
MJPG Streamer Version: svn rev: exported
---------------------------------------------------------------
Help for input plugin..: UVC webcam grabber
---------------------------------------------------------------
The following parameters can be passed to this plugin:

[-d | --device ].......: video device to open (your camera)
[-r | --resolution ]...: the resolution of the video device,
can be one of the following strings:
QSIF QCIF CGA QVGA CIF VGA
SVGA XGA SXGA
or a custom value like the following
example: 640x480
[-f | --fps ]..........: frames per second
[-y | --yuv ]..........: enable YUYV format and disable MJPEG mode
[-q | --quality ]......: JPEG compression quality in percent
(activates YUYV format, disables MJPEG)
[-m | --minimum_size ].: drop frames smaller then this limit, useful if the webcam produces small-sized garbage frames may happen under low light conditions
[-n | --no_dynctrl ]...: do not initalize dynctrls of Linux-UVC driver
[-l | --led ]..........: switch the LED "on", "off", let it "blink" or leave
it up to the driver using the value "auto"

 
Help for output_file.so plugin:
[email protected]:~# mjpg_streamer --output "output_file.so --help"
MJPG Streamer Version: svn rev: exported
---------------------------------------------------------------
Help for output plugin..: FILE output plugin
---------------------------------------------------------------
The following parameters can be passed to this plugin:
[-f | --folder ]........: folder to save pictures
[-m | --mjpeg ]........: save the stream to an mjpeg file
[-d | --delay ].........: delay after saving pictures in ms
[-s | --size ]..........: size of ring buffer (max number of pictures to hold)
[-e | --exceed ]........: allow ringbuffer to exceed limit by this amount
[-c | --command ].......: execute command after saving picture
[-i | --input ].......: read frames from the specified input plugin
 
Help for output_http.so plugin:

[email protected]:~# mjpg_streamer --output "output_http.so --help"
MJPG Streamer Version: svn rev: exported
---------------------------------------------------------------
Help for output plugin..: HTTP output plugin
---------------------------------------------------------------
The following parameters can be passed to this plugin:

[-w | --www ]...........: folder that contains webpages in flat hierarchy (no subfolders)
[-p | --port ]..........: TCP port for this HTTP server
[-c | --credentials ]...: ask for "username:password" on connect
[-n | --nocommands ]....: disable execution of commands

 
 
 
 
 
Viewing from Browser
Use this syntax http://ipaddress:8080/?action=snapshot for viewing. Manually refresh the browser is required in order to see next picture.
http://192.168.1.1:8080/?action=snapshot
http://192.168.1.1:8080/?action=stream
It is better to use Google Chrome for viewing. You will facing problem if using Internet Explorer, it prompt you for saving the file instead of show you the picture. 
 
 
Delphi TCP Video Viewer
Here I provide an application with source code which develop using Delphi for viewing in real time. I didn't write all the code, it just modify from blitzaffe code.

Delphi Video Viewer

 

Viewing from VLC Media Player
You  may want to use VLC Media Player to view the video.
  • Download & run VLC Media Player
  • Select Media -> Open Network Stream...
  • Enter http://192.168.1.1:8080/?action=stream for network URL
 
Viewing from Browser in Real Time
  • Extract the file to your computer
  • Rename www folder to camwww
  • Copy the camwww to www folder of router, you have /www/camwww inside your router
  • Start mjpg_streamer as below
mjpg_streamer -i "input_uvc.so -r 640x480 -f 24" -o "output_http.so -p 8080 -w /www/camwww"
  • Viewing video from browser as below. You shoud see video on your screen.
http://192.168.1.1:8080/javascript_simple.html
  •  Or this one (require java to install on computer)
http://192.168.1.1:8080/java_control.html
  •  Or this one (the main program)
http://192.168.1.1:8080/
 Viewing from Browser

 

 

Authentication
Edit /etc/config/mjpg-streamer, add option password user:myPassword at the end of settings. So the user name will be user and password will be myPassword.

config mjpg-streamer core
option device "/dev/video0"
option resolution "704x480"
option fps "5"
option port "8080"
option enabled "true"
option password user:myPassword

 

Edit /etc/init.d/mjpg-streamer. Change settings as below

start() {
config_load mjpg-streamer
config_get device core device
config_get resolution core resolution
config_get fps core fps
config_get port core port
config_get_bool enabled core enabled
config_get password core password
[ $enabled -gt 0 -a -c $device ] && sleep 3 && $SSD -S -m -p $PIDF -q -x $PROG -- --input "input_uvc.so --device $device --fps $fps --resolution $resolution" --output "output_http.so -c $password --port $port" &
}

 

  • Reboot router after making changes
  • Open Google Chrome (Do not use Internet Explorer)
  • Testing with http://192.168.1.1:8080/?action=snapshot or http://192.168.1.1:8080/?action=stream
  • You will see a login screen as shown in figure below.
  • Enter user as User Name
  • Enter myPassword as Password
  • You will see your picture upon enter correct User Name and Password

mjpg-streamer Authentication

 

Read 114716 times Last modified on Sunday, 12 June 2016 10:37

4 comments

Leave a comment

Back to Top