ビデオ ファイルのリストがあり、それらを ffmpeg で変換したいと考えています。これは私のコードです:
public static void ConvertToMp3(String inputPath, String title)
{
String outputpath = "\"D:\\Mp3\\" + title + ".mp3\"";
String _out;
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.FileName = "ffmpeg";
p.StartInfo.Arguments = " -i \"" + inputPath + "\" -vn -f mp3 -ab 192k " + outputpath;
p.Start();
p.StandardOutput.ReadToEnd();
_out = p.StandardError.ReadToEnd();
p.WaitForExit();
if(!p.HasExited)
p.Kill();
Console.WriteLine(_out);
}
正常に動作しますが、この関数をループでn回呼び出すと、あまりにも多くのプロセスが開かれます。一度に 1 つのプロセスだけを開き、完了したら次のプロセスに進みます。