I’m working on writing a program to batch convert video files using HandbrakeCLI as the converter. I’ve got most of it set up and am actually working on passing the file to Handbrake now. I create a new process with the location of HandbrakeCLI and pass the arguments. I also make it so it executes in the same shell. It spins up and then starts to go through the converting and gets to three frames or so and kills itself. I’m using Visual Studio 12 on Windows 8 64 bit. Here’s my code:
static void EncodeVideos()
{
var continueConverting = true;
while (continueConverting)
{
var converted = 0;
if (settings.Optimize == true)
{
videos = videos.OrderBy(x => x.InputSize).ToList();
}
foreach (var v in videos)
{
if (!v.AlreadyConverted())
{
v.CreateOutputPath();
var input = String.Format("-i \"{0}\" ", v.InputPath);
var output = String.Format("-o \"{0}\" ", v.OutputPath);
var preset = String.Format("-Z {0}", settings.Preset);
var convertString = String.Format(" {0} {1} {2}", input, output, preset);
//Converting is not working correctly yet.
var p = new Process();
p.StartInfo = new ProcessStartInfo(settings.HandBrakeLocation, convertString)
{
UseShellExecute = false,
};
p.Start();
p.WaitForExit();
converted++;
}
}
if (settings.Loop == true)
{
if (converted == 0)
{
continueConverting = false;
}
}
else
{
continueConverting = false;
}
}
}
If you would like more context for the code, I’ve put it all on github and you can find it on Github.
Edit: Fixed code
I guess you REALLY don’t want to continue converting!
This looks like it’s incorrect for a start.