TaskRunner/TaskRunner/TaskManager.cs

101 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.IO;
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 = "ffmpeg",
Arguments = $"-f rawvideo -pix_fmt rgb32 -s:v 1024x576 -r 24 -i \"{src}\" -c:v libx264 -pix_fmt yuv420p -y \"{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)
{
if (src.Count == 0)
{
throw new Exception("src list is empty");
}
var task = new TaskCompletionSource<bool>();
var process = new Process
{
StartInfo =
{
FileName = "ffmpeg",
Arguments = $"-f concat -safe \"0\" -protocol_whitelist \"file,http,https,tcp,tls,pipe\" -i - -codec copy -y \"{dest}\"",
RedirectStandardOutput = true,
RedirectStandardInput = true,
UseShellExecute = false,
},
EnableRaisingEvents = true
};
process.OutputDataReceived += (sender, a) => Console.WriteLine(a.Data);
process.Start();
process.BeginOutputReadLine();
foreach (var filename in src)
{
var l = $"file '{filename}'";
Console.WriteLine(l);
process.StandardInput.WriteLine(l);
}
process.StandardInput.WriteLine();
process.StandardInput.Flush();
process.StandardInput.Close();
process.Exited += (sender, args) =>
{
task.SetResult(true);
process.Dispose();
};
return task.Task;
}
}
}