VideoWriter opencv3.0.0 only one image in movie

asked 2016-03-19 18:53:27 -0500

updated 2016-03-22 02:59:41 -0500

berak gravatar image

Hi,

I open a VideoWriter with fps=1, codec used ( 'X', 'V', 'I', 'D' or 'D','I','V','X' or 'M','J','P','G'). AVI created successfully. Then i push 20 differents color images. The result is a video of 20 s => OK. But the first image is displayed during all the movie. The 19 others are not present.

What do I have to do? Is there a specific settings missing?

pseudo-code:

cvSize = 640x480
iVideoWriter.open(filename.c_str(),CV_FOURCC('M','J','P','G'),fps=1,cvSize,color=true);=> return true
...
for (i=0; i<20; i++)
{
cv::Mat matImg;
...
IplImage *iplImg=NULL;     
matImg = cv::cvarrToMat(iplImg); // iplImg contains my image, with the right size
outStream.write(matImg);
cvReleaseImage(&iplImg);
...
}

a loop = 1 unique image

I am using opencv_world300.dll && opencv_ffmpeg300.dll

Thanks

[edit]:

Thanks for your response. I avoid IplImage and use cv::Mat instead. But the result is the same. The first image is present during all the movie, whatever the duration. Here is my full code. What is wrong?

    cv::VideoWriter         iVideoWriter;
    bool color = true;  
    CvSize imgSize = cvSize(640, 480);

    int codec = CV_FOURCC('M', 'J', 'P', 'G');
    iVideoWriter.open("c:\\temp\\video.avi", codec, 1.0, imgSize, color);

    if (iVideoWriter.isOpened() )
    {
        cv::Mat matImg;

        int a = 20;
        int type = CV_LOAD_IMAGE_COLOR;
        while (a > 0) {
            switch (a % 4)
            {
            case 0:
                matImg = cv::imread("D:\\1nb.bmp", type);
                break;
            case 1:
                matImg = cv::imread("D:\\2nb.bmp", type);
                break;
            case 2:
                matImg = cv::imread("D:\\3nb.bmp", type);
                break;
            case 3:
                matImg = cv::imread("D:\\1nb_MB.bmp", type);
                break;
            }

            cout << "a=" << a << ".before convert:" << matImg.depth() << ", " << matImg.channels();

            if (color == false && matImg.channels() != 1)
            {
                cv::Mat colorMat = matImg;
                cv::Mat greyMat;
                cv::cvtColor(colorMat, greyMat, CV_BGR2GRAY);
                matImg = greyMat;
            }
            else if (color == true && matImg.channels() != 3)
            {
                cv::Mat colorMat;
                cv::Mat greyMat = matImg;
                cv::cvtColor(greyMat, colorMat, CV_GRAY2BGR);
                matImg = colorMat;
            }

            cout << ". after convert:" << matImg.depth() << ", " << matImg.channels() << ".";

            _tstring str;
            str = "Display window" + to_string(a);
            cv::namedWindow(str.c_str(), cv::WINDOW_AUTOSIZE);// Create a window for display.
            cv::imshow(str.c_str(), matImg);

            cv::waitKey(1000);

            iVideoWriter.write(matImg);

            a--;
            cout << endl;
        }
        iVideoWriter.release();
    }
edit retag flag offensive close merge delete

Comments

"What do I have to do ? " - avoid using IplImage*, or anything from opencv's legacy c-api in the 1st place.

also, we need your real code, not this pseudo one, to find out

berak gravatar imageberak ( 2016-03-20 01:12:52 -0500 )edit

yes, weird. vlc shows only one image, media-player / irfanview show all 4.

call me puzzled. it works, if fps > 2.0, but below, i get the mentioned problem

berak gravatar imageberak ( 2016-03-22 03:40:14 -0500 )edit

OK I will try to find another way. Thanks for your time.

mickael_biardeau gravatar imagemickael_biardeau ( 2016-03-22 15:16:56 -0500 )edit