我希望能做类似这样的事情。
ffmpeg -i audio.mp3 -f flac - | oggenc2.exe - -o audio.ogg
我知道如何使用.NET中的Process类运行
ffmpeg -i audio.mp3 -f flac
,但我该如何将其导入到oggenc2中呢?有任何关于这个问题的示例(不一定是ffmpeg或oggenc2)都可以。
我希望能做类似这样的事情。
ffmpeg -i audio.mp3 -f flac - | oggenc2.exe - -o audio.ogg
ffmpeg -i audio.mp3 -f flac
,但我该如何将其导入到oggenc2中呢?好的,我写了以下代码来实现这个功能:
Process ffmpeg = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "ffmpeg.exe",
Arguments = "-i audio.mp3 -f flac -",
UseShellExecute = false,
RedirectStandardOutput = true,
WindowStyle = ProcessWindowStyle.Hidden
}
};
Process oggenc2 = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "oggenc2.exe",
Arguments = "- -o audio.ogg",
UseShellExecute = false,
RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Hidden
}
};
ffmpeg.Start();
oggenc2.Start();
int bufferLength = 4096;
var input = oggenc2.StandardInput.BaseStream;
var output = ffmpeg.StandardOutput.BaseStream;
using (BinaryWriter writer = new BinaryWriter(input))
{
using (BinaryReader r = new BinaryReader(output))
{
byte[] buffer = new byte[bufferLength];
int bytesRead;
do
{
bytesRead = r.Read(buffer, 0, bufferLength);
writer.Write(buffer, 0, bytesRead);
} while (bytesRead > 0);
}
}
ffmpeg.WaitForExit();