Automate Your PC's Media Library
Automatically Convert Your Videos, Continued
An app called Alert and Convert that works with Handbrake tries to do the same thing as the batch file described here, but I wasn't able to get it to work 100 percent of the time.
So we've posted a batch-file template in the PCWorld Downloads library, called Automatic Batch Video Conversion. Note that batch files can do lots of things to your PC, and if you're not careful you might be converting a lot of videos.
Right-click on the convertvideotemplate.bat file and select Edit to open it up in Notepad. You should see this:
@for /r %%F in (*.[filetype], *.[filetype]) do (
"[location of handbrake CLI]" -i "%%F" -o "%%~pnF-ipod.mp4" --preset="iPhone & iPod Touch"
move /-y "%%F" "[location of processed videos dir]")
@for /r %%X in (*ipod.mp4) do
(move /-y "%%X" "[location of Automatically Add To iTunes folder]")
start "" "[Location of iTunes app]"
In order to adapt this batch file to work on your PC, you're going to need to fill out each of the bracketed expressions with your own information: For [filetype], put the three-letter suffix of the kinds of files you want Handbrake to process. If I put in (*.mp4, *.flv, *.3gp, *.avi), that means Handbrake will look for all MPEG-4, Flash Layer Video, 3GP, and AVI files.
For [Location of Handbrake CLI], you'll need the path to the Handbrake CLI app. It's typically in the same folder as the Handbrake GUI app, so just right-click on the Handbrake icon in your Start Menu and copy the location. You should end up with something like "C:\Program Files\Handbrake\HandBrakeCLI.exe".
If you're converting your video to something other than an iPod Touch/iPhone format, you'll want to replace the --preset="iPhone & iPod Touch" with a different set of encoding instructions. Here's a list of Handbrake's different preset encodes.
We want to put the original files somewhere else once they're done being processed, or else this script will convert them again on the next go-round. I made a folder on my desktop called "Processed Videos" and pasted that into the [location of processed videos dir] section.
iTunes 9 and later has a folder called Automatically Add To iTunes; we'll use this folder to add our new movies to the iTunes Library. You can find it by going into your User folder and selecting Music, iTunes, iTunes Media, Automatically Add To iTunes. Copy this file path into the [location of Automatically Add To iTunes folder].
Finally, find the path to the iTunes application itself--typically "C:\Program Files\iTunes\iTunes.exe"--and paste that in the [Location of iTunes app] spot. Assuming your iPod Touch is synced to your PC, iTunes should automatically sync on launch.
Once completed, your script should look something like this:
@for /r %%F in (*.mp4, *.flv, *.3gp, *.avi) do (
"C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%F" -o "%%~pnF-ipod.mp4" --preset="iPhone &amp;amp; iPod Touch"
move /-y "%%F" "C:\Users\pmiller.PCWORLD\Desktop\Processed Videos")
@for /r %%X in (*ipod.mp4) do
(move /-y "%%X" "C:\Users\pmiller.PCWORLD\Music\iTunes\iTunes Media\Automatically Add to iTunes")
start "" "C:\Program Files\iTunes\iTunes.exe"
Now, we have a script that will grab all the videos of a certain type, pass them off to Handbrake, and add them to iTunes when they're done--try and run it with some sample files if you haven't already. Make sure to put the script in the directory you want it to watch for new videos before proceeding any further.
Next, we just need to get it to run automatically. Enter Windows Task Scheduler, which you can find in Control Panel, Administrative Tools, Task Scheduler.
Start by clicking Create Basic Task on the right-hand side. Give it a quick name and description, click Next , and specify how often you want this task to run--we'll say Daily--and a time you want it to run (ideally a time when you're not using the computer, so you don't have to worry about the CPU getting bogged down by converting video).
Click Next again, leave it on Start a program, click Next , and paste the name of the directory you want the batch file to watch over in the Start in (optional) field. (You may need to put the path in quotes if there are spaces in any of the folder names.)
Next: Video Podcasts