Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kill ffmpeg/ffprobe processes if parent .NET application exits #333

Open
lostmsu opened this issue May 20, 2022 · 2 comments
Open

Kill ffmpeg/ffprobe processes if parent .NET application exits #333

lostmsu opened this issue May 20, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@lostmsu
Copy link
Contributor

lostmsu commented May 20, 2022

More generally, if .NET process that launched ffmpeg exits, ffmpeg does not, and there's no option to make it. Most annoying when stopping the .NET app from debugger, as the app has no chance to do anything.

Now I considered contributing this, but

  • would like to consult with maintainer first on how to approach it (esp. with Instances project)
  • too lazy to port this to Unix-like OSes

On Windows in a similar situation this did the trick: https://gist.github.com/lostmsu/a806fbfedf7a3dba184c4e3d38dc5110

@rosenbjerg rosenbjerg added the enhancement New feature or request label Feb 4, 2023
@rosenbjerg rosenbjerg changed the title FFmpeg keeps running when I stop debugging Kill ffmpeg/ffprobe processes if parent .NET application exits Feb 4, 2023
@hqkirkland
Copy link

I’m trying to do something similar— I’m building a .NET Core Worker that reads a streaming schedule, and uses this (AWESOME!!) wrapper lib to handle all the commands.

I tried to use the stoppingToken provided by ExecuteAsync as the option for CancellableThrough, but stopping my debugging doesn’t stop the ffmpeg process. This is a pain because I’m an (overly) aggressive debugger & I keep needing to kill it manually.

My guess was that VS is just ending the main process and not truly “stopping” the service, thus ffmpeg continues.. but I’m not sure. Not currently at home to investigate.

Btw side note: is Console output for the child process supported? I’d like to use the built-in Logger for worker services to monitor the process.

@pedrosbanioles
Copy link

If you are using .NET Framework, you could perhaps hook into the AppDomain.ProcessExit, you would of course need to try to include a reference to your CancellationTokenSource in order to send the cancellation. (https://stackoverflow.com/a/1119869/2573213 may help)

If using .NET core, you could hook into the IApplicationLifetime at startup and add a handler for the OnApplicationStopping event (see here for example: https://stackoverflow.com/a/74956744/2573213). Same principal of accessing the CancellationTokenSource to send the cancellation would apply

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants