0

Is there a way to know the size of an avi video in OpenCV? There are some videos that are blank and instead of processing them I want to get rid of them by comparing their size to a threshold. For example, if the size of the video is 200 kB or less, then I skip processing that video.

Update:

     CvCapture *capture = cvCreateFileCapture(path);
     IplImage *img = cvQueryFrame( capture );  

All videos have the same number of frames but some videos have all blank frames.

fmvpsenior
  • 197
  • 7
  • 22

2 Answers2

0

You can get number of frames by getting CV_CAP_PROP_FRAME_COUNT video property using GetCaptureProperty:

CV_CAP_PROP_FRAME_COUNT Number of frames in the video file.

To get size of file (video) there is another API - depends on your system (WinAPI, POSIX etc). For example on Windows it's GetFileSizeEx() function.

Also look at this SO discussion.

Community
  • 1
  • 1
ArtemStorozhuk
  • 8,715
  • 4
  • 35
  • 53
0

If you want to get the actual file size, you will have to use fopen() or stat as OpenCV doesn't store this information in a cvCapture object. However, you can detect blank videos like so:

CvCapture *capture = cvCaptureFromAVI( argv[1] );
int numFrames = (int) cvGetCaptureProperty(&capture, CV_CAP_PROP_FRAME_COUNT);

Then just decide if it's blank based on the number of frames.

Relevant Documentation:

http://opencv.willowgarage.com/documentation/reading_and_writing_images_and_video.html?highlight=cvcapture#getcaptureproperty

If the file size is different for the blank videos, but the files have the same number of frames, it's due to video compression via keyframing. That means the best way to detect blank frames is via getting the file size, which is outside of the scope of OpenCV and can easily be accomplished using plain C/C++:

#include <sys/stat.h>
...
struct stat st;
stat(avi_filename, &st);
size = st.st_size;
Alex W
  • 37,233
  • 13
  • 109
  • 109