Yeah HandBrakeInterop isn't the easiest API to just write some code for; it's more geared toward full encoder GUIs right now; it doesn't fall back on defaults very well. You had a really good idea in just taking the EncodingProfile from the XML.
Here's a working, minimal project that interacts with HandBrakeInterop: http://engy.us/misc/HandBrakeInteropExample.zip
Some relevant bits:
instance = new HandBrakeInstance();
instance.Initialize(verbosity: 1);
instance.ScanCompleted += instance_ScanCompleted;
instance.StartScan(SourceFile, previewCount: 10);
- 1 is the default verbosity. The "5" you were passing in isn't valid.
- You'll probably want to pass in a real value for the previewCount on StartScan: it uses these static previews to do things like automatic cropping detection and combing detection.
var job = new EncodeJob { EncodingProfile = profile, RangeType = VideoRangeType.All, Title = 1, SourcePath = SourceFile, OutputPath = AppDomain.CurrentDomain.BaseDirectory + "Output.mp4", ChosenAudioTracks = new List { 1 }, Subtitles = new Subtitles { SourceSubtitles = new List(), SrtSubtitles = new List() } };
- You need to pass in which title to encode (1-based index). For files this is rarely relevant; the feature is designed for DVD/Blu-ray scans.
- You have to pass in both a
RangeType
and the specifics for the range: for example if you pick aRangeType
ofFrames
then you need to specifyFramesStart
andFramesEnd
.RangeType.All
is easiest since you don't need to specify anything extra. - You need to specify a list of the chosen audio tracks indices (1-based). Not normally useful for files, but for DVD/Blu-ray discs that have multiple languages.
- Right now you have to give it something under Subtitles or it will crash out. This is actually a bug; there were a few cases I wasn't guarding correctly. I'll fix this up in the future.
Check out VidCoder if you want to see a full reference implementation of the API. HandBrake has started to use it some but it hasn't gotten around to all the features like static previews and pause/resume.
Update: The code required now looks completely different and targets HandBrake.ApplicationServices.dll. New minimal project: http://engy.us/misc/HBInteropExampleV3.zip
A notable difference is that the encode job is now specified in JSON. This is the exact same JSON blob that is spit out in the encode log in HandBrake/VidCoder, so you can steal it from there and tweak it.