MiaoRong / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

OpenCVFrameGrabber#getLengthInTime returns the wrong value for certain videos #236

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Load OpenCVFrameGrabber with a video that is 134 seconds long
2. Call getLengthInTime on that video

What is the expected output? What do you see instead?

Expected output is 134000000 (not sure why the JavaCV convention is 
microseconds, but that's what FFmpegFrameGrabber would give), actual output is 
a negative number.

What version of the product are you using? On what operating system?

I'm using JavaCV-0.1 on Linux. Other than the fact that OpenCVFrameGrabber has 
issues on Windows, this issue can occur on all OSs and it is still in 
JavaCV-0.2.

The bug is due to how small Integer.MAX_VALUE microseconds is in minutes (about 
35 minutes). This is compounded by the order of operations in the function. 
getLengthInFrames returns an integer, so the numerator can easily be too large 
(if the video is minutes long instead of seconds long). This the code:
getLengthInFrames() * 1000000 / getFrameRate()

Hopefully the rounding error is clear at this point - if not I'm happy to 
expound. Replacing that expression with the following should fix it:
getLengthInFrames() / getFrameRate() * 1000000

Original issue reported on code.google.com by william.macrae@gmail.com on 24 Aug 2012 at 11:45

GoogleCodeExporter commented 9 years ago
Thanks for spotting, will fix.

As to why I settled on microseconds, well, FFmpeg, libdc1394, FlyCapture, and 
OpenKinect all use microseconds, only about opencv_highgui uses milliseconds, 
and I don't recommend its use.

Original comment by samuel.a...@gmail.com on 28 Aug 2012 at 2:19

GoogleCodeExporter commented 9 years ago
Ok, it should all be fixed in JavaCV 0.3, thanks for reporting! Let me know if 
it's still not working correctly though, thanks!

Original comment by samuel.a...@gmail.com on 5 Nov 2012 at 11:38