45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Diagnostics;
|
|
|
|
namespace Encoder.Lib;
|
|
|
|
public class EncodeWorker
|
|
{
|
|
private readonly ProcessStartInfo startInfo;
|
|
|
|
public EncodeWorker(string workingDirectory, string inputFile, string outputFile, string encodeParam)
|
|
{
|
|
var arguments = $"-y -i \"{inputFile}\" {encodeParam} \"{outputFile}\"";
|
|
this.startInfo = new ProcessStartInfo()
|
|
{
|
|
FileName = "ffmpeg",
|
|
WorkingDirectory = workingDirectory,
|
|
Arguments = arguments,
|
|
UseShellExecute = false,
|
|
RedirectStandardOutput = true,
|
|
RedirectStandardError = true,
|
|
CreateNoWindow = true,
|
|
};
|
|
}
|
|
|
|
public async ValueTask<int> Run()
|
|
{
|
|
try
|
|
{
|
|
Console.WriteLine($"{this.startInfo.FileName} {this.startInfo.Arguments}");
|
|
using Process? process = Process.Start(this.startInfo);
|
|
if (process is null)
|
|
{
|
|
throw new FileNotFoundException();
|
|
}
|
|
|
|
await process.StandardError.ReadToEndAsync().ConfigureAwait(false);
|
|
await process.WaitForExitAsync().ConfigureAwait(false);
|
|
return process.ExitCode;
|
|
}
|
|
catch
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
}
|