OpenCV2.4 VideoWriter Create single frame video out of image file

asked 2016-05-21 01:15:08 -0600

int main() {
    //simple example I came up with to test out my understanding of the library 
    IplImage* img = cvLoadImage("img1.jpg", CV_LOAD_IMAGE_UNCHANGED);
    CvSize imgSize = cvGetSize(img);
    cv::Mat frame = cv::cvarrToMat(img); //will be used to write on the videowriter
    cv::VideoWriter writerNew("out.avi", CV_FOURCC('M', 'J', 'P', 'G'), 20, imgSize, true);
    if (!writerNew.isOpened())
        std::cout << "FAIL";
        return -1
    return 0;


Program runs. But the video file I get is corrupted(I cannot open-play it).

I wish I got an error message to guide me. However since I get no error message, I am completely lost.

edit retag flag offensive close merge delete