Search This Blog

Saturday 11 September 2010

Automatic Video Transcoding with HandbrakeCLI

Q&A

A customer, Kai, asked a few questions on our forum how he could configure WatchDirectory's Start any Program task to run Handbrake on newly detected video files. He was able to figure out most of it himself (what do *I* know about video conversion?) after a few tips.

HandBrake is a highly popular open-source, GPL-licensed, multiplatform, multithreaded video transcoder, available for MacOS X, Linux and Windows. It includes a command line version, called HandbrakeCLI which allows for easy automation when used together with WatchDirectory or File Viking's Run Action.

Settings

Here you see Kai's setting for his WatchDirectory task. He uses a rather long line for "Parameters for this program", so here is the plain text version:

-i "%WD_FILE%" -f mp4 -w 720 -l 400 -e x264 -b 1000 -2
     -a 1 -E faac -6 dpl2 -R 48 -B 128 -D 0.0 -v 1
     -o "C:\Converted Videos\%WD_FILE_B%.mp4"

I added a few linebreaks, but obviously they should be on 1 line. You will notice he uses 2 variables:

  • %WD_FILE% - this will be replaced by the full path of the detected file by WatchDirectory.
  • %WD_FILE_B% - this will be replaced by just the name of the detected file.

The full list of supported variables

Important Setting

When you are transcoding videos with Handbrake and WatchDirectory like this, please be aware that video transcoding is a very slow, time consuming process. WatchDirectory has no way of knowing if a program started by it is "hanging" or just busy working. In this case Kai has set "Wait for program to exit" to 14400 seconds (4 hours), which should be more than enough if you run this on a reasonably modern computer. If you set this too low, WatchDirectory will "kill" the Handbrake process prematurely.

If you disable "Wait for program to exit" and multiple video's are detected by WatchDirectory, WD will start multiple Handbrake processes to transcode multiple video files. This is only advised for the most powerful computers.

If you use File Viking

File Viking's Run Action can also run HandbrakeCLI, but its environment variables have slightly different names:

  • %FV_FILE% - this will be replaced by the full path of file you dropped on the File Viking basket.
  • %FV_FILE_B% - this will be replaced by just the name of the dropped file.

File Viking currently always waits for the program to exit, there is no need to set a timeout.

No comments: