nager / Nager.VideoStream

Get images from a network camera stream or webcam
MIT License
55 stars 10 forks source link

ffmpeg.exe not shutting down on application crash #6

Closed JPasterkampRotec closed 2 years ago

JPasterkampRotec commented 2 years ago

Context

Running on Windows 10 and .NET framework 4.8

This is how I start the video stream:

stopTokenSource = new CancellationTokenSource();
Client = new VideoStreamClient();
Client.NewImageReceived += Client_NewImageReceived;
var inputSource = new StreamInputSource(streamUrl);
streamReadingTask = Client.StartFrameReaderAsync(inputSource, OutputImageFormat.Bmp, stopTokenSource.Token);

And this is how it is stopped and disposed:

stopTokenSource?.Cancel();
stopTokenSource?.Dispose();
stopTokenSource = null;

if (Client != null)
    Client.NewImageReceived -= Client_NewImageReceived;

Problem

When closing my application normally, the videostream is stopped and dealt with accordingly. However, when an unexpected exception occurs and the application crashes, ffmpeg.exe will still be running. This is causing a lot of issues for me, mainly because the TCP ports used by my application will remain open until ffmpeg.exe is shut down manually through the Task Manager.

Solution

The problem can be solved by either:

tinohager commented 2 years ago

I have push a new package, thanks for your feedback