Ask Your Question
0

VideoCapture unable to read large AVI files (wrong frame count)

asked 2016-07-13 10:40:23 -0600

B4silio gravatar image

updated 2016-07-13 12:35:35 -0600

Hey there!

CONTEXT

In our projects we work with very large video files (5-6h of recordings at a time). We usually encode in MJPEG to make moving through the videos more reasonable (using ffmpeg), which gives us files of 30Gb or thereabouts each time.

PROBLEM

When using VideoCapture to read the avi files, using the following code :

VideoCapture input = VideoCapture(pathString);
if (!input.isOpened()) return;
int frameCount = input.get(CV_CAP_PROP_FRAME_COUNT);

We get the wrong amount of frames (~14'300 frames instead of the correct ~400'000-500'000). VideoCapture is then able to read through the file but only up to frame #14'300 or thereabouts. The problem happens on both linux and osx.

WHAT WE TRIED

The (now deprecated) CvCapture reads the file size properly and allows to read through the entire videos with no issues. Our only problem is that it's much slower to read the files compared to VideoCapture (same files, same machines). (It is our current fallback solution.)

The "trick" from the examples code (reading the file size "manually" off the avi RIFF header) returns the same wrong frame count as getting CV_CAP_PROP_FRAME_COUNT off VideoCapture. This comes, I guess, from the 2gb limit that AVI files had in the old days, but as CvCapture (in both opencv2 and opencv3) is able to read the files properly, I guess that the 2gb limit is not (or should not be) a deal breaker.

THE QUESTION

Any ideas on how to get VideoConverter to work properly? If that is not possible then how to know the proper file size from an over-sized avi file? And barring that any idea on an alternative way of reading through videos in a quicker way than CvCapture?

Any help would be greatly appreciated!

Best, Basilio

edit retag flag offensive close merge delete

Comments

There seem to have been someone with a similar problem 4 years ago with a previous version of opencv, which had at the time been resolved: http://answers.opencv.org/question/14... Unfortunately I doubt that "switching compiler" works here since I'm having the exact same problem on multiple machines and both OSX and linux...

B4silio gravatar imageB4silio ( 2016-09-21 23:35:02 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-09-30 05:23:37 -0600

B4silio gravatar image

updated 2016-09-30 06:52:41 -0600

After further testing, the issue with length appears only with MJPEG encoded AVI files and seems to be related to this bug with the internal mjpeg decoder.

If we change container to mp4 (via ffmpeg -i input.avi -vcodec copy output.mp4) the ffmpeg mjpeg decoder kicks in instead and there are no problems with frame count anymore. However the scrubbing speed (reading video randomly jumping around) is about 60% slower...

Would be great if if some opencv code fairy finds time to work on that I guess...

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2016-07-13 10:40:23 -0600

Seen: 2,917 times

Last updated: Sep 30 '16