AForge.NET

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

Webcam and framerate

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

Webcam and framerate

Postby mdr » Sun Feb 12, 2012 5:41 pm

Hello.

I am wondering if it's possible using AForge to capture video devices (such as webcam) in C# WPF and record the video stream at 25FPS?

I then want to write 25 images per second from the capture video stream. Any help or pointing in the right direction would be much appreciated.

Thank you.
mdr
 
Posts: 4
Joined: Sun Feb 12, 2012 5:35 pm

Re: Webcam and framerate

Postby andrew.kirillov » Sun Feb 12, 2012 6:50 pm

Hello,

You may take a look at samples provided with the framework, which show how to get video out of webcam. But those samples are done using WinForms, so WPF stuff is left for you.
With best regards,
Andrew


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

Re: Webcam and framerate

Postby mdr » Mon Feb 13, 2012 10:07 pm

Thanks Andrew.

EDIT:

I've managed to record live video as described in the samples and I'm using the {videoPlayer}_NewFrame event to capture each Bitmap and output each frame as a .jpg file. Within that event I am using VideoFileWriter at 10FPS to write each frame and when I playback the finished .avi file it is fine at 10FPS as my webcam is operating at slightly higher.

I guess the question is if I can detect the webcam framerate programatically as I really want to record the stream and create the .avi file at the highest FPS possible depending on the camera being used? If that can't be achieved I'll stick to a safe FPS for now.

Thanks.
mdr
 
Posts: 4
Joined: Sun Feb 12, 2012 5:35 pm

Re: Webcam and framerate

Postby andrew.kirillov » Tue Feb 14, 2012 5:35 am

1) The VideoCapabilities property should give you some information about supported video sizes and frame rates. The you can try setting it using DesiredFrameRate property.
2) If you use WriteVideoFrame() method specifying time stamp, then you should be able to get similar playing speed as you had during acquisition.
With best regards,
Andrew


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

Re: Webcam and framerate

Postby mdr » Thu Feb 16, 2012 11:48 pm

Hi Andrew,

I've now managed to write video using the VideoWriter and play it back with the same speed and framerate so thanks for your help there.

Within the VideoPlayer_NewFrame event I write out a .jpg file of the frame image after writing the videoframe to a .avi or .wmv file. These .jpgs are then used to create a video using FFMpeg which should be a direct replicate of the one that was just recorded initially.

However I'm having real trouble with FFMpeg (from command prompt) in playing back the image array into a video that matches the speed of the recorded file. Do you provide any functionality for this at all within AForge? At the moment the video from the images after running FFMpeg is roughly half the length of the recorded video which means it's playing back at roughly double the speed after creation.

Thanks for your help.
mdr
 
Posts: 4
Joined: Sun Feb 12, 2012 5:35 pm

Re: Webcam and framerate

Postby andrew.kirillov » Fri Feb 17, 2012 9:25 am

mdr wrote: Do you provide any functionality for this at all within AForge?

For what? AForge.NET framework has nothing to do with FFMpeg comand line tools.
With best regards,
Andrew


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

Re: Webcam and framerate

Postby mdr » Fri Feb 17, 2012 9:38 am

andrew.kirillov wrote:
mdr wrote: Do you provide any functionality for this at all within AForge?

For what? AForge.NET framework has nothing to do with FFMpeg comand line tools.


Sorry, it was late last night and I should have explained better.

Basically, everything is working fine for me as far as recording and playing back video is concerned. But part of what I want to achieve is use ffmpeg to create image array from my recorded .wmv file.

At the moment after writing each video frame I also use a combination of Bitmapsource and JpegBitmapEncoder to create a .jpg image per frame and then I use FFMpeg to create another video from those images within windows. The problem is that those created .jpg images won't have the same quality of doing it using FFMpeg within the command prompt because I can't use the same switches that ffmpeg provides such as -qscale and the bitrate option.

So my question is - Is it possible within the AForge.Video.FFMPEG assembly to create images for each frame of the video in the Videoplayer NewFrame event rather than creating the images myself with slightly lower quality?
mdr
 
Posts: 4
Joined: Sun Feb 12, 2012 5:35 pm

Re: Webcam and framerate

Postby andrew.kirillov » Fri Feb 17, 2012 10:01 am

mdr wrote: Is it possible within the AForge.Video.FFMPEG assembly to create images for each frame

Current API of AForge.Video.FFMPEG allows saving video files. It does not create images.

mdr wrote:creating the images myself with slightly lower quality?

The question is then why do you create images with lower quality? If it is because .NET does so when save JPEGs, then may google and find the way how to change JPEG compression quality.
With best regards,
Andrew


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




Return to AForge.NET Framework