Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handbrake: save custom preset/encoding command out for use on handbrake-cli on another machine

I have a bunch of videos to convert, from flv to mp4. In the Handbrake gui, in Ubuntu, i've got all my settings sorted out. I've saved it as a preset called "all-tablets".

I need to use HandBrakeCLI on a different ubuntu machine, that's command line only. So, i have two options i can see, and i can't work out how to do either of them:

1) See what the settings used by the handbrake gui are, so i can copy them and use directly with HandBrakeCLI, replacing filenames as necessary.

2) Save out my "all-tablets" preset in such a way that i can copy it to the other machine and use it with HandBrakeCLI there.

Option 2 seems nicer. When i list the available presets in HandBrakeCLI, it doesn't list my custom one, suggesting that the GUI version saves them to somewhere different to the cli version.

Any suggestions? thanks, Max

like image 407
Max Williams Avatar asked Dec 20 '22 19:12

Max Williams


2 Answers

I actually ended up figuring this out: i tried the Windows version of Handbrake in a Windows 7 virtual machine. In windows, the GUI version is just a wrapper for the CLI, unlike Linux where they are two totally seperate things. (i'm not sure what the situation on Mac is).

I first tried importing the preset plist file that i'd saved out of the linux version, but the windows gui couldn't parse it properly, or wasn't happy with it anyway: it seemed to be treating one of the boolean values as if it was a variable name (ie trying to do something like true = "foo"): i couldn't work out what was causing this in my plist file: side by siding it with one saved out of windows, it looked fine.

So, i started from scratch in the windows GUI. The interface is styled a little differently, but I was able to set all the options i have in my linux gui. Then i did a conversion with these settings: because the windows gui uses the CLI version, you can see the command sent to the cli in the conversion log. I copied this, and tried the same set of options in the linux CLI, and it worked fine.

I never thought i'd write this as an answer to any question, but the answer seems to be "Use windows" ;-) Who'd a thunk it.

like image 195
Max Williams Avatar answered Dec 22 '22 12:12

Max Williams


~/.ghb/presets has your GUI presets stored as a PropertyList (it is a kind of XML document). You can take the settings from here and translate them into command line arguments for the CLI. Sadly the CLI does not read the GUI's config file or any other config. If you can code in C(++), adding that support would probably not be too hard. The CLI lives in test/test.c in the Handbrake source tree.

Here is a quick and dirty bit of Python to get you started. Plist.py can be found here http://winappdbg.sourceforge.net/blog/PList.py:

#!/usr/bin/env python                                                                                                    
import sys

import PList

def translate(item):
    args = []

    if "AudioList" in item:
        args.append(("-E", item["AudioList"][0]["AudioEncoderActual"]))

    return args

def invoke(args):
    print "HandbrakeCLI " + " ".join(" ".join(arg) for arg in args)

presets = sys.argv[1]
name = sys.argv[2]

data = PList.fromstring(open(presets).read())

for item in data:
    if isinstance(item, dict):
        if 'PresetName' in item:
            if item['PresetName'] == name:
                invoke(translate(item))

Good luck and have fun.

like image 24
Sean Perry Avatar answered Dec 22 '22 12:12

Sean Perry