VideoWriter issue: class not opening. (c++ with windows8)

asked 2013-09-13 04:14:00 -0600

Hello.

I am trying to record a video using openCV's class VideoWriter.

Using the following function,

void addFrameToVideo(Mat& frame)
{
    if(_vid.open("test.avi", CV_FOURCC('M','J','P','G'), 30, frame.size(), 1))
        cout << "here" << endl;

    _vid.write(frame);
}

_vid is a variable of type VideoWriter and I can imshow frame with no problems.

The if condition never verifies, since the program never outputs "here". However, this code actually creates a "test.avi" file in the directory, but it remains empty. I've tried several different compression methods with no success.

Any thoughts?

edit retag flag offensive close merge delete

Comments

no idea, what goes wrong in your case, but opening a new writer per frame is definitely the wrong way.

think of it, after the 1st time, there's already a file named "test.avi", so before that got closed properly, you can't open a new one.

berak gravatar imageberak ( 2013-09-13 06:17:20 -0600 )edit

I tried to open it out of the loop, in the class constructor and then I simply write the frame into VideoWriter each loop, but the result was the same.

Is it possible that the problem is related to the codec? I've installed VLC, which has all kind of codecs but, once again, no success was achieved.

Ah, another curious thing is that if the filename doesn't have the extension ".avi", no file is created.. weird.

Pedro Batista gravatar imagePedro Batista ( 2013-09-13 06:29:13 -0600 )edit