I'm taking snapshot using LibVLC library.
I'm using following code to save VlcVideoSourceProvider
public Dictionary<string, VlcVideoSourceProvider> sourceProvider;
Then using following code to create and playing player in WPF application:
ThreadPool.QueueUserWorkItem(_ =>
{
var localSourceProvider = sourceProvider[CameraNumber];
if (localSourceProvider.MediaPlayer == null)
{
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
var libDirectory = new DirectoryInfo(Path.Combine(currentDirectory, "libvlc", IntPtr.Size == 4 ? "win-x86" : "win-x64"));
localSourceProvider.CreatePlayer(libDirectory);
localSourceProvider.MediaPlayer.Audio.Volume = 0;
localSourceProvider.MediaPlayer.SnapshotTaken += (sender, e) =>
{
dispatcher.BeginInvoke((Action)(() =>
{
//Not getting this log
log.Info($"MediaPlayer.SnapshotTaken on file: {e.FileName}, {e.ToString()}");
}));
};
if (!camera1.MediaPlayer.IsPlaying())
camera1.MediaPlayer.Play(new Uri("rtsp://admin:[email protected]:554/Streaming/channels/101"));
}
});
After that following code to take snapshot. TakeSnapshot is always returning true but not saving the image on the directory.:
public void TakeImage(string cameraName, string path)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var url = path + "\\" + an_unique_file_name.jpg;
FileInfo fileInfo = new FileInfo(url);
try
{
VlcVedioSourceProvider vlcVedioSourceProvider = sourceProvider.GetValueOrDefault(cameraName);
if (vlcVedioSourceProvider.MediaPlayer != null)
{
var isSnapshotTaken = vlcVedioSourceProvider.MediaPlayer.TakeSnapshot(fileInfo);
//Here isSnapshotTaken is always returning true but fileInfo?.Exists is always false.
log.Info($"isSnapshotTaken: {isSnapshotTaken}, fileExists: {fileInfo?.Exists}");
}
else
{
log.Info($"MediaPlayer is null");
}
}
catch (Exception ex)
{
log.Error($"Error", ex);
throw ex;
}
}
Using following version of library:
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
....
<PropertyGroup>
<ItemGroup>
<PackageReference Include="VideoLAN.LibVLC.Windows" Version="3.0.11" />
<PackageReference Include="Vlc.DotNet.Wpf" Version="3.1.0" />
</ItemGroup>
This code was working fine. Suddenly it stopped working. What might be the cause and solution?