비디오 파일 목록이 있으며 ffmpeg로 변환하려고합니다.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 번 루프에서이 함수를 호출 할 때, 너무 많은 프로세스를 엽니 다 : 이것은 내 코드입니다. 한 번에 하나의 프로세스 만 열어서 끝나면 다음 프로세스로 이동합니다. 프로세스 수를 확인하고 그 이하 (예 2) ×
int process = 0;
foreach (System.Diagnostics.Process myProc in System.Diagnostics.Process.GetProcesses())
{
if (myProc.ProcessName == "process name")
process++;
if (process < 2)
p.Start();
}
'p.WaitForExit();'는 프로세스가 종료 될 때까지 스레드를 대기 상태로 설정해야합니다. ffmepg가 새로운 프로세스를 생성합니까? 명령 줄에서이 명령을 실행하면 어떻게됩니까? 트랜스 코드가 끝날 때까지 기다리지 않습니까? – JohnD
예, 기다리는 중 ... –