Logans Lessions #2: Scripting Handbrake in Windows
The ScenarioYou want to rip some of your movies to your computer. You want to do this to either 1) watch the
movies on something that doesn't have an optical drive, or 2) you want to make your entire DVD/BR
archive available without needing to dig out the physical DVD's each time you play them.
With this in mind, how exactly do you go from ripping a DVD onto the computer, to viewing it on any of these devices? Its not very hard actually, although there is no really streamlined way of doing it as of yet (its not built into any OS that I'm aware of).
First you need to rip the DVD to your hard drive. I would suggest an ISO format (the literal image
file of the DVD, exactly the same space on disk, for exactly the same quality and features). There
are programs out there that can actually play these iso files, and if you have no storage limitations, then this is the easiest way to store your DVD's. If this is what you want, you simply stop here.
For the rest of us that have to worry about storage space, or want a more portable and
generally more useful file you might want something else. An ISO of a typical DVD is close to 8GB.
Depending on the size of your movie collection that could be a huge issue. And no portable device I
know plays ISO.
So, if you want to keep the original source file quality, but want the resulting file to be smaller
and more widely playable what do you do? You encode that file into something else. The tool that
many people use to do this encoding/compression is called "handbrake". Handbrake is a free program, and it allows you to take an ISO file or a folder full of VOB files (the other way to get everything off of a DVD), and compress it into much smaller space.
Using Handbrake is pretty simple, with the hardest part being understanding all of the options that
are available to you. Compressing movies is also a pretty time consuming task. A typical movie can
take anywhere from 20 minutes to 2 hrs depending on the options that you select, and the processing
power of your computer.
However, if you have a large Movie library ready, it can be really tedious to compress each movie
one at a time. Luckly, the people at handbrake have already thought about that, and have created a
command line version of the tool that can be scripted. For those that don't know, scripting is a
generic term for taking something that we do on the computer, and then automating it in an attempt
to reduce the amount of human interaction that is required. In this case, we'll be automating the
process of compressing movies in one folder, and then outputing them to an output folder.
Handbrake scripting on a windows machineSince I'm a bit of a windows guy (as are most of the people out there... by numbers at least), and
when I searched about on the internet for examples of a someone scripting handbrake on windows, the results were remarkably thin, I thought I would do the internet a favor and share with everyone the little script I made to make my life easier.
Powershell is my language of choice, and if you're not already familiar with the old school windows
command prompt (and even if you are), I'd suggest learning powershell as it is rapidly gaining traction as the way to do things in a windows world. I'm about even in my knowledge of cmd and powershell, but I prefer to work with powershell if given the choice.
I'll provide the template script, and explain some of it as I go. Please keep in mind that I am not
a one of microsofts "scripting guys", nor do I proclaim myself as any sort of expert at scripting.
Instead, I'm just sharing something I made in my spare time, and hope that it may be of use to
Also, as you look at the script in detail, you'll see that I'm creating .mkv files. I prefer using them, as I have found better results with them on my surround sound setup than with MP4. However, MP4 is much more widely accepted and played (almost everything will play MP4 files), so if you want MP4, then all you have to do is change the file ending here in my script.
So all you need to do is to copy and paste that script into a blank notepad file (press and hold the
windows key and then press "R", then in the prompt that comes up type "notepad" and press enter).
Change whatever settings you want (file paths, handbrake settings, etc) and then name it whatever
you would like, as long as you remember to save it as a ".ps1" (powershell) file.
After that, you'll likely only run into one other small "problem" running the script. Powershell by
default is not very trusting (read, more secure), so when you first try to run this script, you'll
likely get a message saying that it cannot be run because the execution policy of the machine does not allow it. Luckily, this is an easy fix. Just type this into an elevated (meaning, run-as administrator) prompt.
Set-executionpolicy -executionpolicy remotesigned
Then after that, try to run your script again, and everything should be peachy.
The wrapupAnd there you have it. Now you can start off handbrake to run while you sleep, and you'll have all
those movies converted and compressed in no time :). If you want to get really fancy, you could even
adapt the script to run as a scheduled task, so that anytime you upload files to a folder, it could
convert them, move the outputs to the correct location, and then delete the input file. However, the
core functionality is here in my template.
Feel free to post up and changes or adaptations here, I'd love to see what others come up with :).