DOS Script for Joining JPGs in Multiple Subdirectories Into an AVIThis is a small DOS script that I wrote that turns JPGs from multiple subdirectories into a single AVI (movie).
This script requires that mencoder be installed.
When I capture a series of JPG pictures on my Canon A650 camera using
CHDK with an intervalometer script, they are stored on the SD card like this:
123CANON
124CANON
125CANON
126CANON
As you can see above, pictures are stored in each subsequent *CANON directory. The pics are spread out across many directories because this camera formats the SD card in DOS (12-bit) format which can only contain a limited number of files (JPGs) per directory.
When I copy the SD card contents to my hard drive, my file system setup looks like this:
C:\Timelapse
- 2010-08-10
- 123CANON
| IMG_9012.jpg
| IMG_9013.jpg
| IMG_9014.jpg
| ...
- 124CANON
| IMG_0001.jpg
| IMG_0002.jpg
| IMG_0003.jpg
| ...
- 125CANON
| IMG_2001.jpg
| IMG_2002.jpg
| IMG_2003.jpg
| ...
- 126CANON
| IMG_4001.jpg
| IMG_4002.jpg
| IMG_4003.jpg
| ...Now, the problem is this: In order to turn all these pictures into a movie, you have to put them into a single directory and have them named so they sort according to their creation date (actually the "last modified" date is more reliable).
I run a custom script from this directory (I call this a "date-root" directory because it is the root directory for a specific date):
C:\Timelapse\2010-08-10and it performs this sequence of events:
(1) Rename files in all subdirectories (like "123CANON", etc.) to date-modified (like "2010-08-10_11-23-53.jpg"). This ensures that the files are joined in the right order by mencoder in step 3.
(2) Copy all files from all subdirectories (like "123CANON", etc.) up one level to the date-root directory (in this example: "2010-08-10"). This is required because mencoder needs all joined files to be in a single directory.
(3) Use mencoder to join all JPG files in the date-root directory into a single AVI movie.I wrote the following script so you can do all these steps with a single command. Just run the script in the date-root directory (like C:\Timelapse\2010-08-10). A movie file called "_movie.avi" will be created in the current directory. This is your final movie with all JPGs joined together. This file can be uploaded directly to YouTube as is.
If you make a mistake, you can run the script more than once in the same directory with no ill effects.
To use this script, your computer must meet the following requirements:
(1) Have mencoder installed
(2) Have rtrenamefiles installed
(3) Have the system "PATH" variable point to both of the above executable (EXE) programs. (Do this from Control Panel > System > Advanced - depends on operating system)If you want the movie to have a title, just create a file called "_title.srt" in the date-root directory with the format described in a previous post on this thread. You will also have to make sure the -font argument of mencoder points to a valid font on your computer.
To use this batch file, just copy the following text and place it into a file called jpg-to-avi.bat. Make sure the Windows environment variable PATH points to it (see above).
:: JPG to AVI by Russ Tanner v 1.00
:: No warranty is expressed or implied.
:: Use at your own risk.
:: Distribute freely.
:: Available at: http://urlbam.com/ha/M002z
@echo off
:: In all subdirectories:
:: (1) Rename each *.jpg file to its modified date.
:: (2) Copy each *.jpg file to its parent directory.
for /d %%x in (*) do (
echo Processing Directory %%x
cd %%x
rtrenamefiles -file-mask *.jpg
for %%y in (*.jpg) do (
echo Copying %%y
copy %%y ..\*
)
cd ..
)
:: Encode all JPGs to an AVI.
mencoder "mf://*.jpg" -o _movie.avi -ovc lavc -lavcopts vcodec=mjpeg -font c:\windows\fonts\verdana.ttf -sub _title.srt -subalign 2 -subfont-autoscale 0 -subfont-text-scale 16