AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

VideoRecorder with 60FPS

Forum to discuss AForge.NET Framework, its features, API, how-tos, etc.

VideoRecorder with 60FPS

Postby Ronin » Mon Oct 30, 2017 3:03 pm

Hi,

i'm a total noob and i'm trying to write a webcam recorder that can record with 60FPS from my webcam. I have a Logitech C922 Pro which supports 60FPS in 720p mode.

I followed the standard tutorials to build the recorder and everything works fine except that all videos are 30FPS.

After searching for the video devices with

Code: Select all
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);


i select one camera from a combo box
Code: Select all
            foreach (FilterInfo device in videoDevices)
            {
                comboBox1.Items.Add(device.Name);
            }


Next i have another combobox where i list all modes the camera has to offer

Code: Select all
        private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
        {
            videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);

            for (int i=0; i<videoSource.VideoCapabilities.Length; i++)
            {
                comboBox2.Items.Add("["+Convert.ToString(i)+"]:"+videoSource.VideoCapabilities[i].FrameSize.ToString()+" at "+videoSource.VideoCapabilities[i].MaximumFrameRate +"FPS" );
            }

        }


Here the 60FPS mode for 720p is displayed correctly. All other modes are displayed as 30FPS (or even 2FPS for very good resolution).

Then i select the 60FPS mode and catch the frames with "videoSource_NewFrame"

Code: Select all
private void videoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap image = (Bitmap)eventArgs.Frame.Clone();
            pictureBox1.Image = image;   
            ImArray[countframes % ImArray.Length] = image;
            countframes++;
        }


With each frame i do two things:

1) i display it in a picture Box
2) i save it in an array (ImArray) for export


when i record a stopwatch with the camera i can clearly see that the data was recorded with 30FPS. Also the

Code: Select all
videoSource.VideoCapabilities[cameramode].AverageFrameRate.ToString()

shows 30FPS.


Does anyone has an idea what i'm doing wrong?
Is Aforge fast enough for 60FPS?
Is there some special setting? I find it a bit confusing since i though that i grab every frame from the camera with the event "videoSource_NewFrame".

Thanks
Ronin
Ronin
 
Posts: 2
Joined: Mon Oct 30, 2017 2:42 pm

Re: VideoRecorder with 60FPS

Postby andrew.kirillov » Mon Oct 30, 2017 9:14 pm

Hello Ronin,

Don't have a 60 FPS camera to test, so hard to say for sure. If you just display the camera (its video frames), can you see them coming at the 60 FPS rate? Is your NewFrame event hanler called 60 times a second?
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: VideoRecorder with 60FPS

Postby Ronin » Tue Oct 31, 2017 6:21 pm

If you just display the camera (its video frames), can you see them coming at the 60 FPS rate?

Well it's hard to tell by the eye but...

what i can do is
to display the AverageFrameRate in a textBox

Code: Select all
fpsBox.Text = videoSource.VideoResolution.AverageFrameRate.ToString() + " FPS of " + videoSource.VideoResolution.MaximumFrameRate.ToString() + " FPS";


which gives me
1) 30 FPS of 30 FPS in any other 30 FPS mode
2) 30 FPS of 60 FPS in my desired mode.

I'm relatively new to c# so if you have some better method to look at the FPS dont hesitate

Is your NewFrame event hanler called 60 times a second?


I don't know! apparently not... how do i find out how often its called? naively i would have expected it is called everytime a new frame is available...though the name eventhandler...

I tested the camera with other camera software (e.g. OBS Studio) and there it records at 60FPS. So i don't think its the hardware...


EDIT:
On the other hand when i change the Exposure time of the camera to ridiculously long times i can clearly see that the real fps drop BUT
the display still says 30FPS! This is strange... How is the "AverageFrameRate" determined? can i calculate it myself with some timer?

So what i do is to set all camera properties by the recorder

Code: Select all
                    videoSource.SetCameraProperty(AForge.Video.DirectShow.CameraControlProperty.Exposure, -2, AForge.Video.DirectShow.CameraControlFlags.Manual);
                    videoSource.SetCameraProperty(AForge.Video.DirectShow.CameraControlProperty.Focus, 0, AForge.Video.DirectShow.CameraControlFlags.Manual);
                    videoSource.SetCameraProperty(AForge.Video.DirectShow.CameraControlProperty.Zoom, 100, AForge.Video.DirectShow.CameraControlFlags.Manual);
                    videoSource.SetVideoProperty(AForge.Video.DirectShow.VideoProcAmpProperty.BacklightCompensation, 0, AForge.Video.DirectShow.VideoProcAmpFlags.Manual);
                    videoSource.SetVideoProperty(AForge.Video.DirectShow.VideoProcAmpProperty.Contrast, 128, AForge.Video.DirectShow.VideoProcAmpFlags.Manual);
                    videoSource.SetVideoProperty(AForge.Video.DirectShow.VideoProcAmpProperty.Gain, 160, AForge.Video.DirectShow.VideoProcAmpFlags.Manual);
                    videoSource.SetVideoProperty(AForge.Video.DirectShow.VideoProcAmpProperty.WhiteBalance, 5920, AForge.Video.DirectShow.VideoProcAmpFlags.Manual);
                    videoSource.SetVideoProperty(AForge.Video.DirectShow.VideoProcAmpProperty.Sharpness, 128, AForge.Video.DirectShow.VideoProcAmpFlags.Manual);
                    videoSource.SetVideoProperty(AForge.Video.DirectShow.VideoProcAmpProperty.Saturation, 128, AForge.Video.DirectShow.VideoProcAmpFlags.Manual);

Exposure has values ranging from -2 which is the longes integration time (with the eye i would say it corresponds to ~2FPS)
to -11 which is the shortest integration time.
even when i set the exposure to -11 i dont have 60FPS
from other software i know that -7 or smaller is needed for 60FPS.


EDIT 2:

Ok i have added a stopwatch into the "videoSource_NewFrame" event handler

The elapsed time is ~32ms ==> 30 fps
when i increase the exposure the elapsed time increases to as much as 210ms.





EDIT 3:

Just when i was about to give up i stumbled upon the following

https://stackoverflow.com/questions/41046188/how-to-set-camera-fps-in-opencv

The guy in the thread had the exact same problem in c++ and opencv. His camera should have been able to work with 60fps but it didn't.

He claims that
cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));

did the trick because his camera works with mjpeg compression.

Now back to my c# / aforge code:

http://support.logitech.com/en_gb/article/Set-up-C922-Pro-Stream-Webcam-for-XSplit?product=a0q3100000B2PiyAAF
states that the c922 also works with the Color Space/Compression — MJPG .


But since then i have not found a way to use that knowledge for a setting in aforge. Can someone tell me if there is a comparable setting?

Thanks
Ronin
 
Posts: 2
Joined: Mon Oct 30, 2017 2:42 pm

Re: VideoRecorder with 60FPS

Postby mfrench » Tue Apr 16, 2019 10:01 pm

Have you found a solution for this issue? I have ran into the exact same problem...

I am using the latest version of aforge with the Logitech C922x web camera.

When I list the capabilities of the device I see a single setting with:
- Maximum FPS: 60
- Resolution: 1080/720
- Average FPS: 30

After setting the videosource.VideoResolution to the capability above I only get 30 fps out of the camera.

The camera itself is advertised to run at 60fps at 1080/720 - is this a limitation of aforge? Is there any work around? Please help!
mfrench
 
Posts: 1
Joined: Tue Apr 16, 2019 9:58 pm

Re: VideoRecorder with 60FPS

Postby andrew.kirillov » Wed Apr 24, 2019 9:24 am

mfrench wrote:is this a limitation of aforge? Is there any work around?

Looks like AForge.NET Framework's limitation. It chooses to use average FPS. It does not provide way to set custom. Unless you do some code changes.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3427
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to AForge.NET Framework