FFMpeg and Panasonic BL-C11 IP web cam to automatically create time lapse video
I decided that I should keep snapshots off my Panasonic IP webcam every 2 seconds over the holidays. I set the IP webcam's internal software to drop of an image on my FTP server using the configuration software built into the camera. I primarily did this as a security measure for our house. I also created a script on my linux box to delete any images older than 2 weeks. I set this up to run once a day as a cron job.
If there ever was an security question or issue we had 640x480 images of (about 20,000 images at 44KB apiece) our house covering the past 2 weeks safely stored on my server.
Then I got the idea by playing with Picasa, that it would be cool to build these into a time lapse video sequence that I would make avaiable on my website. Needless to say after playing around with various tutorials and scripts I have something that works really well. The once daily updated finished product is available here:
http://gpigs.trebacz.com/Office_Cam.htm (embedded flash version of the movie using flowplayer free player running on my web server)
http://gpigs.trebacz.com/PigCam/OfficeCam2.mpg (mpeg video for download and playing on just about anything that doesn't support flash
The biggest challenge was that the images out of the web cam's filename are a timestamp of when the image was captured. FFMPEG is a great open source linux program to automatically turn still shots into a video, but the files need to be sequentially numbered.
#Creates soft links to all the Web Cam jpgs to a temp folder, renames the softlinks sequentially so FFMPEG can create the video streams (mpeg and flash video), and then deletes the temp folder
#Create a temprary directory underneath for symbolic links
mkdir /home/david/.ffmpeg_temp
#change to the temporary directory
cd /home/david/.ffmpeg_temp
#Create sequentially numbered softlinks of all the images in the temporary directory from SMB mounted Windows 2000 server
\ls /home/david/Trebacz/web_sites/Gpigs_Trebacz_Com/PigCam/OfficeCam*.jpg | perl -nwe 'chomp; next unless -f $_; $r=sprintf "OfficeCam%06d",$i++;print `ln -s "$_" $r.jpg`'
#Convert the sequentially numbered files into a mpg and flv movie in the temp folder
ffmpeg -f image2 -b 2000k -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -pass 1/2 -y -i ./OfficeCam%06d.jpg ./OfficeCam2.mpg
ffmpeg -f image2 -b 2000k -y -i ./OfficeCam%06d.jpg ./OfficeCam.flv
# Copy video file from temporary directory to Windows 2000 server overwriting existing file
cp -f ./OfficeCam2.mpg /home/david/Trebacz/web_sites/Gpigs_Trebacz_Com/PigCam/
cp -f ./OfficeCam.flv /home/david/Trebacz/web_sites/Gpigs_Trebacz_Com/PigCam/
#change to the main directory
cd
#delete the temporary directory
rm -rf /home/david/.ffmpeg_temp
External web resources to get me there:
1. General overview of FFMpeg http://ffmpeg.org/faq.html#SEC14
2. How to create time lapse video using FFmepeg http://pr0gr4mm3r.com/linux/how-to-create-a-time-lapse-video-using-ffmpeg/
3. Flash player installed on your weberver to display embedded flash video's in web pages http://flowplayer.org/download/index.html
If there ever was an security question or issue we had 640x480 images of (about 20,000 images at 44KB apiece) our house covering the past 2 weeks safely stored on my server.
Then I got the idea by playing with Picasa, that it would be cool to build these into a time lapse video sequence that I would make avaiable on my website. Needless to say after playing around with various tutorials and scripts I have something that works really well. The once daily updated finished product is available here:
http://gpigs.trebacz.com/Office_Cam.htm (embedded flash version of the movie using flowplayer free player running on my web server)
http://gpigs.trebacz.com/PigCam/OfficeCam2.mpg (mpeg video for download and playing on just about anything that doesn't support flash
The biggest challenge was that the images out of the web cam's filename are a timestamp of when the image was captured. FFMPEG is a great open source linux program to automatically turn still shots into a video, but the files need to be sequentially numbered.
#Creates soft links to all the Web Cam jpgs to a temp folder, renames the softlinks sequentially so FFMPEG can create the video streams (mpeg and flash video), and then deletes the temp folder
#Create a temprary directory underneath for symbolic links
mkdir /home/david/.ffmpeg_temp
#change to the temporary directory
cd /home/david/.ffmpeg_temp
#Create sequentially numbered softlinks of all the images in the temporary directory from SMB mounted Windows 2000 server
\ls /home/david/Trebacz/web_sites/Gpigs_Trebacz_Com/PigCam/OfficeCam*.jpg | perl -nwe 'chomp; next unless -f $_; $r=sprintf "OfficeCam%06d",$i++;print `ln -s "$_" $r.jpg`'
#Convert the sequentially numbered files into a mpg and flv movie in the temp folder
ffmpeg -f image2 -b 2000k -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 100 -pass 1/2 -y -i ./OfficeCam%06d.jpg ./OfficeCam2.mpg
ffmpeg -f image2 -b 2000k -y -i ./OfficeCam%06d.jpg ./OfficeCam.flv
# Copy video file from temporary directory to Windows 2000 server overwriting existing file
cp -f ./OfficeCam2.mpg /home/david/Trebacz/web_sites/Gpigs_Trebacz_Com/PigCam/
cp -f ./OfficeCam.flv /home/david/Trebacz/web_sites/Gpigs_Trebacz_Com/PigCam/
#change to the main directory
cd
#delete the temporary directory
rm -rf /home/david/.ffmpeg_temp
External web resources to get me there:
1. General overview of FFMpeg http://ffmpeg.org/faq.html#SEC14
2. How to create time lapse video using FFmepeg http://pr0gr4mm3r.com/linux/how-to-create-a-time-lapse-video-using-ffmpeg/
3. Flash player installed on your weberver to display embedded flash video's in web pages http://flowplayer.org/download/index.html
Comments
Post a Comment