TaskRunner/TaskRunner/TaskManager.cs

86 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace TaskRunner
{
public class TaskManager
{
public Task RunGnash(string src, string dest)
{
var task = new TaskCompletionSource<bool>();
var process = new Process
{
StartInfo =
{
FileName = "dump-gnash",
Arguments = $"-1 -D \"{dest}\" \"{src}\"",
RedirectStandardOutput = true,
UseShellExecute = false
},
EnableRaisingEvents = true
};
process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data);
process.Start();
process.Exited += (sender, args) =>
{
task.SetResult(true);
process.Dispose();
};
return task.Task;
}
public Task swfRawToMp4(string src, string dest)
{
var task = new TaskCompletionSource<bool>();
var process = new Process
{
StartInfo =
{
FileName = "avconv",
Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p \"{dest}\"",
RedirectStandardOutput = true,
UseShellExecute = false
},
EnableRaisingEvents = true
};
process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data);
process.Start();
process.BeginOutputReadLine();
process.Exited += (sender, args) =>
{
task.SetResult(true);
process.Dispose();
};
return task.Task;
}
public Task Mp4Join(IList<string> src, string dest)
{
var task = new TaskCompletionSource<bool>();
var process = new Process
{
StartInfo =
{
FileName = "avconv",
Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p \"{dest}\"",
RedirectStandardOutput = true,
UseShellExecute = false
},
EnableRaisingEvents = true
};
process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data);
process.Start();
process.BeginOutputReadLine();
process.Exited += (sender, args) =>
{
task.SetResult(true);
process.Dispose();
};
return task.Task;
}
}
}