Fix the deadlock of ffmpeg process on Windows

This commit is contained in:
nyanmisaka 2022-06-16 03:45:32 +08:00
parent 8d766a1476
commit 606bec35c5

View File

@ -114,9 +114,14 @@ public static class Chromaprint
var info = new ProcessStartInfo(ffmpegPath, args) var info = new ProcessStartInfo(ffmpegPath, args)
{ {
WindowStyle = ProcessWindowStyle.Hidden,
CreateNoWindow = true, CreateNoWindow = true,
UseShellExecute = false,
ErrorDialog = false,
// We only consume standardOutput.
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true RedirectStandardError = false
}; };
var ffmpeg = new Process var ffmpeg = new Process
@ -125,7 +130,6 @@ public static class Chromaprint
}; };
ffmpeg.Start(); ffmpeg.Start();
ffmpeg.WaitForExit(timeout);
using (MemoryStream ms = new MemoryStream()) using (MemoryStream ms = new MemoryStream())
{ {
@ -139,6 +143,8 @@ public static class Chromaprint
} }
while (bytesRead > 0); while (bytesRead > 0);
ffmpeg.WaitForExit(timeout);
return ms.ToArray().AsSpan(); return ms.ToArray().AsSpan();
} }
} }