Skip to content

Commit

Permalink
fix: killing ffmpeg processes on windows
Browse files Browse the repository at this point in the history
Fix for killing FFMPEG processes spawned by FFMP on Windows
  • Loading branch information
massimo-rnd committed Feb 5, 2025
1 parent 0eeef33 commit 1bf7632
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
26 changes: 26 additions & 0 deletions FFMP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Management;
using CommandLine;

class FFMP
Expand Down Expand Up @@ -45,6 +46,31 @@ static void Main(string[] args)
Console.WriteLine($"Process already terminated or invalid: {ex.Message}");
}
}

// Additional fix for Windows: Kill all FFmpeg processes by name
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
try
{
var ffmpegProcesses = Process.GetProcessesByName("ffmpeg");
foreach (var ffmpegProcess in ffmpegProcesses)
{
try
{
ffmpegProcess.Kill();
Console.WriteLine($"Force-killed FFmpeg process with ID {ffmpegProcess.Id}");
}
catch (Exception ex)
{
Console.WriteLine($"Error killing FFmpeg process {ffmpegProcess.Id}: {ex.Message}");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error retrieving FFmpeg processes: {ex.Message}");
}
}

e.Cancel = true;
Environment.Exit(0);
Expand Down
1 change: 1 addition & 0 deletions FFMP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="System.Management" Version="9.0.1" />
</ItemGroup>

</Project>

0 comments on commit 1bf7632

Please sign in to comment.