2010年3月11日 星期四

motion Webcam

motion Webcam on Mini2440

This is an interesting webcam library that will detect movement object on camera and start capturing the motion picture on mpeg format, there are other feature that allow capture video record into a database and also enable remote control of the webcam through xml-rpc.

The library dependencies is on SDL, ffmpeg, SDL is require because ffplay needs it and ffmpeg also require libz library to build it.

Download a copy from motion and ffmpeg.

Install the ffmpeg first which motion rely on its library.

Configure the package.

./configure --prefix=/usr --libdir=/lib --datadir=/usr/share --enable-shared --enable-cross-compile --arch=arm --cc=arm-linux-gcc --host-ldflags="-L/rootfs/lib" --host-cflags="-I/rootfs/usr/include"


then modify the config.mak in the Makefile to replace gcc, ar, ranlib to prefix it with 'arm-linux-'

Compile and install it to a temporary directory.

make
make install DESTDIR=/install/ffmpeg



There are 2 main directories lib and usr are created.

Copy all the files require to our root filesystem.


cd /install/ffmpeg/usr
cp -ar lib/* /rootfs/lib
cp -ar include/* /rootfs/usr/include
cp bin/* /rootfs/usr/local/bin
cd ../lib
cp pkgconfig/* /rootfs/lib/pkgconfig


Change all the libac* package configure files in /rootfs/lib/pkgconfig as shown below.

prefix=/usr
exec_prefix=${prefix}
libdir=/lib
includedir=${prefix}/include


Now, install the motion webcam library.

Configure the package.

./configure --host=arm-linux --prefix=/usr --sysconfdir=/etc --libdir=/lib -datadir=/usr/share --with-ffmpeg=/rootfs LDFLAGS="-L/rootfs/lib" CPPFLAGS="-I/roofs/usr/include"


Change Makefile to add CPPFLAGS = -I/rootfs/usr/include and insert the flags to all the $(CC) compile line.

Compile and install it.

make
make install DESTDIR=/install/motion



There are 2 directories etc and usr are create.

Copy all the files require to our root filesystem.

cd /install/motion/usr
cp bin/* /rootfs/usr/local/bin
cd ../etc
cp motion-dist.conf /rootfs/etc/motion.conf



Change the motion configuration file below.


ffmpeg_cap_motion off
ffmpeg_timelapse 1
target_dir /tmp/cam1


Restart the board to test the library.

First, check our usb camera is connect and recognize in our board (my is a microdia chip from GDMALL)

dmesg|grep usb

usb 1-1: new full speed USB device using s3c2410-ohci and address 2            
usb 1-1: New USB device found, idVendor=0c45, idProduct=60fc
usb 1-1: New USB device strings: Mfr=0, Product=1, SerialNumber=0
usb 1-1: Product: USB camera
usb 1-1: configuration #1 chosen from 1 choice


Note, the vendor and product id is shown above, if you don't see the message it means the kernel is not configure properly.

Start the motion webcam, it will generate a timelapse mpg output file in the /tmp/cam1 directory.


motion


Go to the output directory to convert it to avi format from the mpeg file to a suitable frame size.

ffmpeg -i 20090103-timelapse.mpg -s 240x320 foo.avi


Finally, view it on device screen.

ffplay -s 240x320 foo.avi


It can be automated to run a serial of commands above to make it as a live video.

For the server process, we can stream over the network and use the browser in our host computer to view it.

First, configure the ffserver.conf to accept flash stream format which i will view it on my pc, below is the important setting.

Fromat swf
VideoBitRate 300
VideoFrameRate 10
VideoSize 320x240
NoAudio


While the motion is still running, i will start up the stream server and use ffmpeg to redirect the motion mpg files into swf and stream it over the network.

ffserver
ffmpeg -i 20090105-timelapse.mpg -vcodec flv -s 320x240 -b
300k -r 10 http://192.168.114.190:8090/feed1.ffm


FFmpeg version 0.5.1, Copyright (c) 2000-2009 Fabrice Bellard, et al.           
configuration: --prefix=/usr --libdir=/lib --datadir=/usr/share --enable-share
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 1 / 52.20. 1
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
built on Mar 11 2010 16:08:38, gcc: 4.4.1
Input #0, mpegvideo, from '20090105-timelapse.mpg':
Duration: 00:00:00.15, bitrate: 104857 kb/s
Stream #0.0: Video: mpeg1video, yuv420p, 320x240 [PAR 1:1 DAR 4:3], 104857 c
Mon Jan 5 06:36:25 2009 192.168.114.190 - - [GET] "/feed1.ffm HTTP/1.1" 200 825
Output #0, ffm, to 'http://192.168.114.190:8090/feed1.ffm':
Stream #0.0: Video: flv, yuv420p, 320x240, q=3-31, 300 kb/s, 1000k tbn, 10 c
Stream mapping:
Stream #0.0 -> #0.0
Press [q] to stop encoding


Note, the above message show that our input is from the motion mpeg and the output it to flv flash format.

Now, go to the pc and type http://192.168.114.190:8090/test1.swf in the browser, you will see the flash movie which is capture earlier in our motion webcam.




沒有留言:

張貼留言