4

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

Max Williams
  • 32,435
  • 31
  • 130
  • 197

2 Answers2

8

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.

Max Williams
  • 32,435
  • 31
  • 130
  • 197
  • Thank you, this is exactly what I was looking for. In mho, it should be the real answer. – gsl Dec 18 '15 at 15:05
3

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

Sean Perry
  • 3,776
  • 1
  • 19
  • 31
  • Thanks Sean, that's really useful info. I'm struggling to convert ghb's options into CLI options though: For example, the first pair is `AudioAllowAACPass `. I'm looking at this page `https://trac.handbrake.fr/wiki/CLIGuide` and i can't find the CLI option corresponding to "AudioAllowAACPass". Does the translation require expert knowledge of audio encoding? – Max Williams Jan 10 '14 at 09:34
  • I am not certain all of them are directly relevant. You will probably need to do some experimentation here. Match all of the ones you can and try it. Then you get to go code hunting for how to match the Property List to the options the CLI exposes. You may need to extend the CLI to handle all of them. – Sean Perry Jan 10 '14 at 18:01
  • That's what i was afraid of :/ It's a bit annoying that the two sets of options are so disparate. I guess i'll be able to figure it out with some scripting which does lots of different versions and uses diff to tell me when i've got the same result as the gui-produced version. Thanks! – Max Williams Jan 13 '14 at 10:15
  • Agreed. I often deal with episodic content so while I would prefer the CLI I tend to use the GUI more. I believe the tool you are working on could be popular. Get it close to working and let the open source world help you make it better. I know I would use it. I have considered writing it before :-) Kids and life though..... – Sean Perry Jan 13 '14 at 16:18