I have succeeded in getting two webcams connected to a Raspberry Pi to work and then making time-lapse movies since several days. The cameras work with higher resolution in Ubuntu on a PC-laptop than in Raspbian on Raspberry Pi B.
Sometimes a camera hangs and then I need to reboot the Raspberry Pi in order to get it to work again. Is there a way to restart the USB webcam without rebooting?
First I test the cameras in Ubuntu and then in Raspbian. After that a bash-script running using crontab is presented. I have blog in Swedish about this:
Ubuntu 14.04: STMicroelectronics Imaging Division (VLSI Vision) Aiptek PenCam 1: gvfs-mount -s gphoto2; sleep 10; LD_PRELOAD=/usr/lib/i386-linux-gnu/libv4l/v4l2convert.so fswebcam -d v4l2:/dev/video1 -i 0 --jpeg 95 -S 5 -r 352x292 test.jpg Works! gvfs-mount -s gphoto2; sleep 10; vgrabbj -d /dev/video1 -w 352 -H 292 -D
7 -f test.jpg Works!Microdia Sweex Mini Webcam LD_PRELOAD=/usr/lib/i386-linux-gnu/libv4l/v4l2convert.so fswebcam -d v4l2:/dev/video1 -i 0 --jpeg 95 -S 20 -r 352x288 test.jpg Works! vgrabbj -d /dev/video1 -i cif -z 20 -D 7 -f test.jpg Works!
Pixart Imaging, Inc. Digital camera, CD302N/Elta Medi@ digi-cam/HE-501A: gvfs-mount -s gphoto2; sleep 10; LD_PRELOAD=/usr/lib/i386-linux-gnu/libv4l/v4l2convert.so fswebcam -d v4l2:/dev/video1 -i 0 --jpeg 95 -S 2 -r 352x288 test.jpg Works! gvfs-mount -s gphoto2; sleep 10; vgrabbj -d /dev/video1 -i cif -D 7 -f test.jpg Works!
Pixart Imaging, Inc. Q-TEC WEBCAM 100: LD_PRELOAD=/usr/lib/i386-linux-gnu/libv4l/v4l2convert.so fswebcam -d v4l2:/dev/video1 -i 0 --jpeg 95 -S 2 -r 352x288 test.jpg Works! vgrabbj -d /dev/video1 -i cif -D 7 -f test.jpg Works!
Chicony Electronics Co., Ltd USB 2.0 Camera (built-in to laptop): fswebcam -d v4l2:/dev/video0 -i 0 --jpeg 95 -S 20 -r 1280x1024 test.jpg Works! vgrabbj -d /dev/video0 -i sxga -z 20 -D 7 -f test.jpg Works!
Raspbian: STMicroelectronics Imaging Division (VLSI Vision) Aiptek PenCam 1: LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l2convert.so fswebcam
-d v4l2:/dev/video0 -i 0 --jpeg 95 -S 5 -r 352x292 test.jpg Works! vgrabbj -d /dev/video0 -w 352 -H 292 -D 7 -f test.jpg Works!
Microdia Sweex Mini Webcam: LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l2convert.so fswebcam
-d v4l2:/dev/video0 -i 0 --jpeg 95 -S 40 -r 352x288 test.jpg Works, but better for lower resolutions. vgrabbj -d /dev/video0 -i sif -z 20 -D 7 -f test.jpg Works!
Pixart Imaging, Inc. Digital camera, CD302N/Elta Medi@ digi-cam/HE-501A: LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l2convert.so fswebcam
-d v4l2:/dev/video0 -i 0 --jpeg 95 -S 20 -r 352x288 test.jpg Works, but gray. vgrabbj -d /dev/video0 -i cif -z 20 -D 7 -f test.jpg Works, but gray.
Pixart Imaging, Inc. Q-TEC WEBCAM 100: LD_PRELOAD=/usr/lib/arm-linux-gnueabihf/libv4l/v4l1compat.so fswebcam -d v4l1:/dev/video0 -i 0 --jpeg 95 -S 20 -F 2 -r 176x144 test.jpg Works, but necessary skipping leads to: "Error synchronising with buffer 0. VIDIOCSYNC: Resource temporarily unavailable". vgrabbj -d /dev/video0 -i qcif -z 20 -D 7 -f test.jpg Works!
Script camera.sh running using crontab: #!/bin/bash PREFIX=/home/pi/camera DATE=$(date +"%Y-%m-%d_%H%M") vgrabbj -d /dev/video1 -w 352 -H 292 -z 5 -D 0 -f $PREFIX/pencam1_$DATE.jpg vgrabbj -d /dev/video0 -i qcif -z 20 -D 0 -f $PREFIX/miniwebcam_$DATE.jpg curl -T "$PREFIX/{pencam1,miniwebcam}_$DATE.jpg" ftp://ftp.mysite.se/mydir/ --user myusername:mypassword if [ ! -s $PREFIX/pencam1_$DATE.jpg -o ! -s $PREFIX/miniwebcam_$DATE.jpg ] ; then /sbin/reboot ; fi # End of camera.sh
Making movies on Raspberry Pi: find . -name 'pencam1_*' -empty | xargs rm -f ls pencam1_*.jpg > pencam1_stills.txt mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=88/73:vbitrate=8000000 -vf scale=352:292 -o pencam1_timelapse.avi -mf type=jpeg:fps=24 mf://@pencam1_stills.txt
find . -name 'miniwebcam_*' -empty | xargs rm -f ls miniwebcam_*.jpg > miniwebcam_stills.txt mencoder -nosound -ovc lavc -lavcopts vcodec=mpeg4:aspect=11/9:vbitrate=8000000 -vf scale=176:144 -o miniwebcam_timelapse.avi -mf type=jpeg:fps=24 mf://@miniwebcam_stills.txt
Download, using other Linux-computer, from Raspberry Pi: scp snipped-for-privacy@dojopi1.local:camera/pencam1_timelapse.avi . scp snipped-for-privacy@dojopi1.local:camera/pencam1_stills.txt . scp snipped-for-privacy@dojopi1.local:camera/miniwebcam_timelapse.avi . scp snipped-for-privacy@dojopi1.local:camera/miniwebcam_stills.txt . ssh snipped-for-privacy@aeblapi1.local 'rm -f camera/*.avi'