Ask Your Question

canterburyTales's profile - activity

2013-11-18 16:37:08 -0600 answered a question VideoWriter Not Working on Some Macintosh Machines

I have a very similar issue, running XCode 5.0.2 on my MacBook Pro 13-inch (Mid 2010) with the latest OS X Mavericks, and openCV 2.4.7. I am trying to write a series of data matrices into a video. The avi file is created with a size of 286 bytes. Then, when I add a single image frame, the file size goes up to 414 bytes. This is far too small for the amount of data that I added to the video file (which makes me sure that the frame isn't added correctly to the video). Indeed, no matter how many frames I then add to the video, the file size remains at exactly 414 bytes until the code terminates. Here is my code:

string filename = "Video from data.avi";
int fps = 20;

VideoWriter *writer = new VideoWriter(filename,CV_FOURCC('M', 'J', 'P', 'G'),fps,cvSize(400,400));

for (int i=0; i<100; i++){

    Mat imgMat(400,400,CV_8UC3);

    (*writer).write(imgMat);
}

No matter what value I use to terminate the for-loop (currently i<100 in the code), the video file is created and remains at 414bytes. Obviously, none of my video players is able to read the file, and they crash or report errors when I try to open the avi file. I have tried the following to no effect: changing the fps to both high and low values; changing the initialisation of the matrix from nothing to various Scalar(r,g,b) values; changing the FOURCC codec to over 100 different values (most of which I am sure I don't have the codec for!).

Any help would be much appreciated! I'm sure I've done something silly...