AForge.NET icon indicating copy to clipboard operation
AForge.NET copied to clipboard

NewFrame not getting called on OBS Virtual Camera

Open Bit00009 opened this issue 3 years ago • 2 comments

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

Bit00009 avatar Mar 19 '21 21:03 Bit00009

Maybe some one find way to fix it and capture obs virtual camera too ?

Katod avatar Apr 23 '22 10:04 Katod

Hi , You must set videoCaptureDevice.VideoResolution before start video.

VideoCapabilities[] vcs = videoCaptureDevice.VideoCapabilities; videoCaptureDevice.VideoResolution = vcs[0]; videoCaptureDevice.NewFrame += VideoCaptureDevice_NewFrame; videoCaptureDevice.Start();

jirunn avatar Oct 06 '23 14:10 jirunn