Nager.VideoStream icon indicating copy to clipboard operation
Nager.VideoStream copied to clipboard

StartFrameReaderAsync can't be stopped when rtsp is offline

Open JPasterkampRotec opened this issue 3 years ago • 4 comments

I'm using Nager.VideoStream for getting frames from a security camera on a Windows 10 PC with a .NET framework 4.8 application.

When the source is offline/not reachable, it is not possible to stop StartFrameReaderAsync. Even when you cancel the provided CancellationToken, StartFrameReaderAsync won't stop. The only way to then stop it, is by closing my entire application.

I reproduced this issue in the Nager.VideoStream.TestConsole by only changing:

  • The input source: var inputSource = new StreamInputSource("my_secret_rtsp_url");
  • The location of the ffmpeg.exe: var client = new VideoStreamClient(@"my_secret_folder\ffmpeg.exe");

The console application clearly cancels the cancellation token:

Console.WriteLine("Press any key for stop");
Console.ReadKey();
cancellationTokenSource.Cancel();

Console.WriteLine("Press any key for quit");
Console.ReadKey();

But this console writeline is never executed:

Console.WriteLine("End Stream Processing");

In my application I need to call StartFrameReaderAsync quite frequently. That means without proper cancellation, multiple StartFrameReaderAsync threads will be active at the same time. This is a major performance issue for my application when the camera is offline/not reachable.

JPasterkampRotec avatar Sep 22 '22 14:09 JPasterkampRotec

In the meantime, have you found a solution to the problem?

tinohager avatar Oct 20 '22 11:10 tinohager

No, but the code keeps hanging at var length = await frameOutputStream.ReadAsync(buffer, 0, buffer.Length); when the source is offline.

I read this old ticket from FFMPEG (https://trac.ffmpeg.org/ticket/2294), which seems to suggest that parameter stimeout solves this issue. I tried this with the Nager.VideoStream.TestConsole and it always immediately times out, even when the source is available and I put -stimeout 123456789 in the ProcessStartInfo arguments. I hope to have sent you in the right direction with this information.

JPasterkampRotec avatar Oct 25 '22 06:10 JPasterkampRotec