This is a timelapse script, which pretty much explains it self. But what it does it, takes a webcam or a url (a http url that points to a jpeg webcam, which has an update image everytime you load the website) and extracts the frame out and names it accordingly so that they are always in the correct order chronologically. Then the script points you at some commands to make the jpg images converted into videos. Mencoder works out to be the best image to video converter in this case.
The Steps
 
1. ssh into a pc with linux and a webcam using putty
2. cd ~
3. mkdir capush
4. cd capush
5. touch capush
6. chmod +x capush
7. vi capush
8. hit i in vi, select all the script/text from below the #!/bin/bash and control C it, then paste by right clicking into the putty shell running vi (which should be in insert mode because you pressed i). Exit and save by pressing escape, and then typing colon, w and q and exclamation point
    RECAP: IN VI: i, IN WEB BROWSER: select script, CONTROL+C, BACK TO VI: Right click into vi (Script should paste), escape, wq!, enter
9. type ./capush to see instructions
10. Example use:
    i.    cd ~
    ii.   apt-get -y install mplayer mencoder wget fswebcam
    iii.  mkdir firstcap
    iv.   cd firstcap
    v.    ~/capush/capush 2 /dev/video0
            Note to find out what your video drive is just type:
            echo /dev/video*
    vi.    mencoder mf://*.jpg -mf fps=10:type=jpg -ovc raw -oac copy -o out10fps.avi
    vii.   mencoder mf://*.jpg -mf fps=20:type=jpg -ovc raw -oac copy -o out20fps.avi
Cool Webcam Commands to Take from the script:
To take one image:
fswebcam -d /dev/video0 -S 10 file.jpg &
To Convert alot of jpgs to a video:
The best is to use mencoder it comes out with the best quality:
mencoder mf://*.jpg -mf fps=10:type=jpg -ovc raw -oac copy -o out10fps.avi
These also work:
cat *.jpg | ffmpeg -f image2pipe -vcodec mjpeg -i – out.mpg
And:
cat *.jpg | avconv -f image2pipe -vcodec mjpeg -r 20 -i – out.mpg
SCRIPT BELOW
 
# !/bin/bash
function printhelp(){
   echo
echo “REQUIREMENTS: ‘apt-get -y install fswebcam wget'”
  echo “USAGE: $0 {int in sec} {url|full path to video dev}”
echo “Both Parameters are necessary: interval in seconds, and input url/device”
echo “Saves to current directory, format is local time: YYMMDD_HH_MM_SS.jpg”
echo “TO STOP CAPTURING: Press CONTROL-C two times”
echo
echo “TIP: For clouds an interval of 5 seconds is good.”
echo “EXAMPLE: $0 5 /dev/video0”
echo “EXAMPLE: $0 5 http://www.aaa.com/image/cam.jpg”
echo “NOTE: You can initiate $0 from anywhere, it will always put the output images into your current directory”
echo ”      If you were to use this command now the images will go to:”
echo ”      $PWD”
echo “NOTE: This app kills any fswebcam or wget process that might be running”
echo
echo “===POST STEPS – CONVERTING JPEGS TO VIDEO:===”
echo “Before running $0 insure nothing else is in this directory, specifically other jpgs – if your going to make a video of them”
echo “STEP 0: First run $0 using the USAGE described above”
echo “ffmpeg, avconv, and mencoder can stich all of these videos – my favorite is mencoder”
echo “STEP 1: cd into directory where the images are, you should already be there”
echo “STEP 2: Pick one of the 3 ways”
echo ”    i.  ‘apt-get -y install ffmpeg'”
echo ”        ‘cat *.jpg | ffmpeg -f image2pipe -vcodec mjpeg -i – out.mpg'”
echo ”    ii. ‘apt-get -y install libav-tools'”
echo ”        ‘cat *.jpg | avconv -f image2pipe -vcodec mjpeg -r 20 -i – out.mpg'”
echo ”        Results are similar to ffmpeg but you can slow down the fps to 20″
echo ”    iii. BEST WAY: ‘apt-get -y install mplayer mencoder'”
echo ”        ‘mencoder mf://*.jpg -mf fps=20:type=jpg -ovc raw -oac copy -o out20fps.avi'”
echo ”        Or you can slow down the frames per second (fps) to 10:”
echo ”        ‘mencoder mf://*.jpg -mf fps=10:type=jpg -ovc raw -oac copy -o out10fps.avi'”
echo
exit
}
# THE MAIN PROGRAM BEGINS HERE
if [ -z “$1” ]; then
printhelp
fi
if [ -z “$2” ]; then
printhelp
fi
framenum=0
echo
echo “=======================================”
echo “=======================================”
echo “Deciding What Type of Video To Capture:”
if `echo $2 | grep -q “^/dev/”`; then
killall fswebcam
echo “Capturing Video Device [int=$1 sec]: $2”
echo “Saving to: $PWD”
echo “=======================================”
echo “=======================================”
  while [ true ]; do
# create a filename with date and time portion
filename=$(date +”%Y%m%d_%H_%M_%S”).jpg
frame=`expr $frame + 1`
echo
echo “=======================================”
echo “=======================================”
echo “Saving Frame #$frame to: $filename”
echo “=======================================”
echo “=======================================”
echo
# use wget to download the current image from the webcam
# fswebcam -d /dev/video0 -S 10 -r 320×240 $D2.jpg
fswebcam -d $2 -S 10 $filename &
# wait 5 seconds
sleep $1;
done;
else
killall wget
echo “Capturing URL Webcam [int=$1 sec]: $2”
echo “Saving to: $PWD”
echo “=======================================”
echo “=======================================”
while [ true ]; do
# create a filename with date and time portion
filename=$(date +”%Y%m%d_%H_%M_%S”).jpg
frame=`expr $frame + 1`
echo
echo “=======================================”
echo “=======================================”
echo “Saving Frame #$frame to: $filename”
echo “=======================================”
echo “=======================================”
echo
# use wget to download the current image from the webcam
wget $2 -O $filename &
# wait 5 seconds
sleep $1;
done;
fi

Leave a Reply

Your email address will not be published. Required fields are marked *