I have a simple WPF application. The application records an RTSP stream to a file. For this purpose Vlc.DotNet library is used.
I have tested the application with two computers and the results are the same for both.
The application code is given below.
public partial class MainWindow : Window
{
private IPath _pathWrapper;
private IDirectoryInfo _vlcLibDirectory;
private VlcMediaPlayer _videoRecorder;
public MainWindow()
{
InitializeComponent();
}
private void OnButtonClick(object sender, RoutedEventArgs e)
{
if (_videoRecorder != null && _videoRecorder.IsPlaying())
{
_videoRecorder.Stop();
Button.Background = Brushes.Blue;
_videoRecorder = null;
return;
}
string currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
_pathWrapper = new PathWrap();
_vlcLibDirectory = new DirectoryInfoWrap(_pathWrapper.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
var options = new string[]
{
"--file-logging",
"--logfile=OnvifVideoRecording.log",
"-vvv"
};
_videoRecorder = new VlcMediaPlayer(_vlcLibDirectory.DirectoryInfo, options);
//string fileDestination = "\\\\\\BuildSrv\\Videos\\A, A, 1\\test.mp4";
string fileDestination = @"D:\Media\Video\A, A, 1\test.mp4";
if (File.Exists(fileDestination))
{
File.Delete(fileDestination);
}
string[] mediaOptions =
{
":sout=#file{dst='" + fileDestination + "'}",
":sout-keep"
};
_videoRecorder.SetMedia("rtsp://192.168.1.110:5504/channel=0,stream=0", mediaOptions);
_videoRecorder.Play();
Button.Background = Brushes.Red;
}
}
The application has a window. The window has a button. When this button is pressed for the first time, recording a video file is started and the button turns red. I usually record video files for 10 minutes. When the button is pressed for the second time, recording a video file is stopped and the button turns blue.
If I record a file to the local destination (to the same computer where the program is run, for example, D:\Media\Video\A, A, 1\test.mp4), everything is ok. Recording video file is started and stopped quickly, almost immediately.
The problems occur when I try to record a file to the remote computer (for example, \BuildSrv\Videos\A, A, 1\test.mp4). Recording a video file starts immediately. However, _videoRecorder.Stop() takes approximately 30 seconds – 1 minute. Resource monitor shows very high network use (90% in case of one computer and 100% in case of another) after the button is pressed for the second time (recording video is stopped). The longer the recorded video file is, the more time is needed to stop VlcMediaPlayer.
Why does stopping VlcMediaPlayer takes so much time in case of recording an RTSP stream to the remote computer? Can this problem be solved somehow?