There is a 1-2 sec lag between the video preview and capture
Summary
There is a 1-2 sec lag between the video preview and capture
Minimal project and steps to reproduce
There is a 1-2 sec lag between the video preview and capture
Code snippet
//Initialization code---
_libVLC = new LibVLC(new string[] { "--no-snapshot-preview", "--no-osd", "--avcodec-hw=d3d11va", "--no-video-title", "--no-audio" });
_mediaPlayer = new MediaPlayer(_libVLC);
_mediaPlayer.EnableHardwareDecoding = true;
_mediaPlayerRecord = new MediaPlayer(_libVLC);
_mediaPlayerRecord.EnableHardwareDecoding = true;
Capture snippet
//Capture code
private void StartVideoRecording()
{
string dshowfps = $":dshow-fps=30";
using (Media _recordMedia = new Media(_libVLC, "dshow://", FromType.FromLocation))
{
_recordMedia.AddOption($":dshow-vdev=Virtual Camera");
{
// diff
_recordMedia.AddOption(dshowfps);
}
List<string> options = Win32Utils.ParseStringOptions(":no-audio|:live-caching=300|:dshow-size=1280x1024|:dshow-aspect-ratio=5:4|:dshow-adev=none|:avcodec-hw=d3d11va", new char[] { '|' });
if (options == null || options.Count == 0)
{
sLogger.Log($"Record option: No Media Options added", Category.Warn);
}
else
{
foreach (string item in options)
{
_recordMedia.AddOption(item);
sLogger.Log($"Record option: {item} added", Category.Debug);
}
}
string destination = Path.Combine(AssemblyDirectory, "AttemptVideo_1.wmv");
string transcode = "#transcode{{vcodec=h264,vb=1500,fps=30,scale=0,acodec=none,ab=128,channels=2,threads=4,high-priority=true}}";
sLogger.Log($"Record option: {transcode} added", Category.Debug);
//string transcode = "#transcode{{vcodec=h264,vb=1500,fps=30,scale=0,acodec=none,ab=128,channels=2,threads=4,high-priority=true}}";
// Only recording mp4 using h264
_recordMedia.AddOption(":sout=" + transcode + ":std{access=file,dst=" + destination + "}");
if (!_mediaPlayerRecord.Play(_recordMedia))
{
MessageBox.Show("Error in Recording...");
}
_mediaPlayerRecord.Playing += _mediaPlayerRecord_Playing;
}
}
private void _mediaPlayerRecord_Playing(object sender, EventArgs e)
{
StartVideoPreview();
_mediaPlayerRecord.Playing -= _mediaPlayerRecord_Playing;
}
private bool StartVideoPreview()
{
bool bResult = false;
if (this._VideoParameters == null)
return bResult;
string dshowfps = $":dshow-fps=30";
// For Capture live feed from Camera device
using (Media _previewMedia = new Media(_libVLC, "dshow://", FromType.FromLocation))
{
_previewMedia.AddOption($":dshow-vdev=Virtual Camera");
{
// diff
_previewMedia.AddOption(dshowfps);
}
List<string> options = Win32Utils.ParseStringOptions(":no-audio|:live-caching=300|:dshow-size=1280x1024|:dshow-aspect-ratio=5:4|:dshow-adev=none|:avcodec-hw=d3d11va", new char[] { '|' });
if (options == null || options.Count == 0)
{
sLogger.Log($"Preview option: No Media Options added", Category.Warn);
}
else
{
foreach (string item in options)
{
_previewMedia.AddOption(item);
sLogger.Log($"Preview option: {item} added", Category.Debug);
}
}
if (!_mediaPlayer.Play(_previewMedia))
{
MessageBox.Show("Error in Previewing...");
}
}
bResult = true;
return bResult;
}
Playback snippet
//Playback code----
string inVideoOutputPath = Path.Combine(AssemblyDirectory, "AttemptVideo_1.wmv");
if (!_mediaPlayer.IsPlaying)
{
using (var media = new Media(_libVLC, new Uri(inVideoOutputPath)))
{
List<string> options = Win32Utils.ParseStringOptions(":file-caching=1|:avcodec-fast");
if (options == null || options.Count == 0)
{
sLogger.Log($"Playback option: No Media Options added", Category.Warn);
}
else
{
foreach (string item in options)
{
media.AddOption(item);
sLogger.Log($"Playback option: {item} added", Category.Debug);
}
}
if (!_mediaPlayer.Play(media))
{
MessageBox.Show("Error in Playing...");
}
}
}
What is the current bug behavior?
There is a 1-2 sec lag between the video preview and capture
What is the expected correct behavior?
There should not be lag between the video preview and capture
Does it work on other plaforms? Does it work with the official VLC apps?
NA
Relevant logs and/or screenshots
[2021-09-15T17:03:14,918-04:00] [54] [WARN ] [Framework.Application.Presentation.VLCWrapper] -- [Warning] dshow:ConnectFilters: No crossBar routes found (incompatible pin types)
[2021-09-15T17:03:15,094-04:00] [17] [WARN ] [Framework.Application.Presentation.VLCWrapper] -- [Warning] dshow:ConnectFilters: No crossBar routes found (incompatible pin types)
[2021-09-15T17:03:18,086-04:00] [44] [WARN ] [Framework.Application.Presentation.VLCWrapper] -- [Warning] mp4:i_length <= 0
[2021-09-15T17:03:51,120-04:00] [29] [ERROR] [Framework.Application.Presentation.VLCWrapper] -- [Error] direct3d11:SetThumbNailClip failed: 0x800706f4
[2021-09-15T17:03:51,562-04:00] [62] [WARN ] [Framework.Application.Presentation.VLCWrapper] -- [Warning] main:no more input streams for this mux
Environment
- OS:
- Version
- Device:
- LibVLC version and architecture
- LibVLCSharp version
OS: Windows 64 bit Version Win10, Device: Virtual Camera LibVLC version and architecture 3.0.11.0 LibVLCSharp version 3.4.9.0 LibVLCSharp.WPF 3.4.9.0