views:

3297

answers:

3

Hi to all,

I'm capturing video from my webcam using OpenCV on MacOSX. It works fine but when I try to play on QuickTime my captured video it plays too fast. i.e. I capture from camera for 10 seconds but when I play on QuickTime the video is 2 seconds.

I've tried to change fps from 25 to 10 and It's works quite fine, but I'm sure it's not the correct process:

CvVideoWriter *writer = 0;  
int isColor = 1;
int fps     = 25;
int frameW  = 640; // 744 for firewire cameras
int frameH  = 480; // 480 for firewire cameras

The problem is that for now I've to capture with WebCam but the real pourpose of program is to capture image from any external source connected to my Mac.

I'm using this code to capture:

for (;;) {
  cvGrabFrame(capture)
  image = cvRetrieveFrame(capture);
  cvWriteFrame( writer, image );
}

Any hint? I'm also showing webcam output on cvNamedWindow, how can I improve quality in this windows?

thanks a lot to all!

Andrea!

+1  A: 

Could be that compressing the captured video and saving it to a file is too CPU intensive. If that's the case then you really only see 10 FPS in the cvNamedWindow, and only 10 FPS are written to the file. Specifiying 25 FPS in the file will naturally speed playback up some.

To see if that's really your problem, you could try to save the image data only in memory. I've not tried it out, but I think you'd do that with cvCloneImage().

You could also try some other format with a lower CPU overhead to save your video:

CV_FOURCC('P','I','M','1')    = MPEG-1 codec
CV_FOURCC('M','J','P','G')    = motion-jpeg codec (does not work well)
CV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codec
CV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codec
CV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codec
CV_FOURCC('U', '2', '6', '3') = H263 codec
CV_FOURCC('I', '2', '6', '3') = H263I codec
CV_FOURCC('F', 'L', 'V', '1') = FLV1 codec
Inshallah
Yes is too CPU intensive, more or less 90% but the problem is also cvShowImage( "Capture", image ); to show image from webcam into a Window. I've tried to hide image during capture but that doesn't resolve the problem. Every mov file is too fast. If I use XCode sample to capture video I've not this problem. I'm using gcc 4-0-1.
Andrea Girardi
A: 

this sounds very interesting.. i am trying to run opencv via JNA in java. works pretty fine, but i couldn't get the video writing done using OSX (but on windows xp it works fine, with the same effect, that the video is 10 seconds but only 2 are displayed when opened in vlc).. could you tell me what kind of codec did you use? and could you tell me if you compiled opencv with just ffmpeg and quicktime disabled?

thanks in advance

kyotoramen
I've still the same problem. I've read on some forum to try to compile OpenCV with ffmpeg library. When I try to reduce fps to 10, the size of video is more or less 45mb for 10 seconds with DIVX codec... I think it's not correct....
Andrea Girardi
so you are also not able to watch the video after recording on osx? it seems kind of strange to me... i read in one of your comments that you are using quicktime for recording on osx, because of design contraints?! is that what you do?
kyotoramen
A: 

I can confirm that 10 fps is standard, although I believe it may be because you don't have a camera which captures at more than 10 fps (which is likely the issue) :)

This is still strange because I'm using waitkey(30), which should be 33fps, but it's precisely 10 :/

Sam