Search code examples
ubuntuhandbrake

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


Solution

  • ~/.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.