jmgomezpoveda / JGaze

Gaze library in Java
1 stars 1 forks source link

JavaCV FFmpegFrameGrabber - ioctl set time per frame failed #10

Open jmgomezpoveda opened 11 years ago

jmgomezpoveda commented 11 years ago

Detail in https://groups.google.com/forum/#!topic/javacv/Nwp2Vd4Rz8I

In one of my webcams I am unable to use the FFmpegFrameGrabber, with another one it works perfectly.

FFmpegFrameGrabber grabber = new FFmpegFrameGrabber(new java.io.File("/dev/video0")); grabber.setFormat("video4linux2"); grabber.setImageWidth(640); grabber.setImageHeight(480); grabber.setFrameRate(30); grabber.start();

I get the error:

[video4linux2,v4l2 @ 0x7f018c1f2d60] ioctl set time per frame(1/30) failed

If I don't call setFrameRate() before start(), the webcam works fine.

Using ffmpeg in the command line, this does not work:

ffmpeg -f video4linux2 -r 30 -s 640x480 -i /dev/video0 -r 30 out.avi

While both the following works:

ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -r 30 out.avi

ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 out.avi

Of course, I could just avoid using setFrameRate() in this webcam, but I want the code generic (for every webcam), and it should use > 30 fps when available (like 125 or 60 fps in the PS3 Eye).

jmgomezpoveda commented 11 years ago

AFAIK, the ffmpeg program doesn't set the actual frame rate specified on the command line, but the closest supported one. From ffmpeg.c: if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) { int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ost->frame_rate = ost->enc->supported_framerates[idx]; } I guess we should be doing something like that in FFmpegFrameGrabber as well. If this fixes the issue your posted on the site, please comment about that there to remind me of adding something like the above, thanks

Samuel

jmgomezpoveda commented 11 years ago

As a workaround, we are only using FFmpeg if the requested framerate is > 30 fps (the OpenCV limitation). This does not solve the issue, but limits its impact only to very high end cameras, when manually requesting that framerate.