AForge.NET
AForge.NET copied to clipboard
NewFrame not getting called on OBS Virtual Camera
Hi I want to access to OBS Studio virtual camera using AForge.NET but it doesn't work properly. It finds it and name and everything is fine but NewFrame is not getting called. I tested the same code with my laptop webcam and it works...
namespace WebCamStudy
{
class Program
{
static FilterInfoCollection filterInfoCollection;
static VideoCaptureDevice videoCaptureDevice;
static Viewer camView = new Viewer();
static void Main(string[] args)
{
Console.WriteLine("Initializing...");
/* ========================================================= */
filterInfoCollection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo Device in filterInfoCollection) Console.WriteLine($"Device [{Device.Name}]");
var FilterInfo = filterInfoCollection[0]; // OBS Virtual Camera
Console.WriteLine($"Connecting to [{FilterInfo.Name}]...");
videoCaptureDevice = new VideoCaptureDevice(FilterInfo.MonikerString);
videoCaptureDevice.NewFrame += OnFrameSync;
videoCaptureDevice.Start();
Console.WriteLine("Syncing...");
camView.ShowDialog();
/* ========================================================= */
Console.WriteLine("Releasing...");
if (videoCaptureDevice.IsRunning == true)
videoCaptureDevice.Stop();
camView.Close();
Console.WriteLine("App finished.");
}
static private void OnFrameSync(object sender, NewFrameEventArgs eventArgs)
{
camView.SetFrame((Bitmap)eventArgs.Frame.Clone());
}
}
}
What is wrong?
- Also there is no VideoSourceError
Maybe some one find way to fix it and capture obs virtual camera too ?
Hi , You must set videoCaptureDevice.VideoResolution before start video.
VideoCapabilities[] vcs = videoCaptureDevice.VideoCapabilities; videoCaptureDevice.VideoResolution = vcs[0]; videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame; videoCaptureDevice.Start();