Tuesday, August 5, 2014

Time lapse & image crunching

Over the past three weeks I have amassed approximately 2200 images. One image taken every 15 minutes. This is far too many files for me to handle with something like GIMP or Photoshop. Thankfully I am not the first person to have this problem, and the internet makes it very easy to find solutions to problems other people have already had.

Each image is approximately 2539 × 3507 pixels, and the orientation is not pleasant to view on a standard widescreen monitor. Further, there is so much activity that trying to view a series of images with everything visible tends to drown out any specific area of interest. So I've taken to cropping down to smaller 1280x720 or 1920x1080 pixel regions.

I've been using the software suite Imagemagick to handle the bulk of this.  For example:
for file in *.jpg; do convert -crop 1920x1080+310+285 $file tc/zleaf_$file; done
This takes every jpg in a given directory: Move to a point 310 pixels in from the left and 285 pixels down from the top, and then crop out an area 1920 pixels to the right and 1080 pixels down.

It places each of these new images in a directory (previously created) called "tc" and labels the new images with the prefix "zleaf_" followed by the original file name. I preserve all the original files and have a separate directory with the new cropped images.

I have been using a few different programs to generate the videos. Originally I started with Apple's free iMovie '09 and an ancient version of Adobe After Effects. iMovie is a breeze to use and After Effects seems to offer more than I could imagine needing for this. However both require me to be involved in the process. They also won't run (easily) on a *nix system.

So I'm working to settle on Mencoder, a part of the Mplayer program used to play videos. Using two commands I'm able to easily (and so far much quicker than iMovie or Adobe After Effects) generate videos:
ls -1tr *.jpg | grep -v files.txt > video.txt
Creates and saves a files called video.txt, it contains a list of all the jpgs in a given directory.
mencoder -idx -nosound -noskip -ovc x264 -x264encopts bitrate=3000 -o video.avi -mf fps=30 'mf://@video.txt' 
Creates a video file that plays back at 30fps with no sound at the same resolution of the source images. It takes ~5 minutes to create a 1920x1080 video out of the 2200 image files, the file size of the resulting video is ~28MB. The original images totaled ~1.8GBs. Video below (recommended playback: Full screen at HD if possible)

The next step in this project (I think) involves
 - Figuring out how to overlay 1cm grid lines
 - Figuring out how to embed a timer
 - Finding a few areas of interest so images can be automatically
 - - Cropped and saved as they are captured (keeping the original intact)
 - - Lists generated for each day of images
 - - Videos generated for each day of images
 - - Compiled video based on each daily video
 - - - http://www.misterhowto.com/index.php?category=Computers&subcategory=Video&article=join_with_mencoder

Various links to places that helped me figure all this out:
 - Converting/Cropping image files
 - Generating timelapse videos with Mencoder

No comments:

Post a Comment