VideoWriter Error

Hello,

I am composing a video from a sequence of images obtained by glob. I am getting many messages for output starting in: INFO[0]. I could not find in internet a specific reason for such message. Could someone help me to see where is the error? The code builds perfectly:

if (BG_images.empty()) {
    std::cout << "check file path";
    system("pause");
}

Size resolution(512, 512);
int fps = 3;

VideoWriter out("Video.avi", VideoWriter::fourcc('D', 'I', 'V', 'X'), fps, resolution, false);
out.write(BG_images);
out.release();
imshow("Video", BG_images);
waitKey(0);

}

I don’t know about that error message, but VideoWriter::write() is supposed to take one image as argument, so you’d need to loop though your images. The same applies to imshow. Also, you may want to to check the actual size of your images.

1 Like

Hi,
There is a good sample here.
Video size must be equal to image size

1 Like

Success! Thank you Matti Vuori and Laurent Berger. Below the code to identify a sequence and save as video .avi.

int main()
{
std::vector< cv::String> f_BG;
glob(“C:/Users/Home/OneDrive/Desktop/BG/*.png”, f_BG, false);
std::vector< Mat> BG_images;
size_t count_BG = f_BG.size();

for (size_t p = 0; p < count_BG; p++) {
    BG_images.push_back(imread(f_BG[p], IMREAD_GRAYSCALE));
}
VideoWriter writer;
int codec = VideoWriter::fourcc('H', 'F', 'Y', 'U');
double fps = 4;                          
std::string filename = "vid.avi";  
int p=0;
writer.open(filename, codec, fps, BG_images[p].size(), false);

for (int p = 0; p < count_BG; p++)
{
    writer.write(BG_images[p]);
}
writer.release();
return 0;

}

Observation: I shoul put inside the loop as Matti sayed, I should change to use de HFYU codec for better video resolution and I should change my IMREAD to GRAYSCALE instead UNCHANGED or ANYDEPTH because the images that I am using with are PNG 16 bit.

The INFO 0 messages still remain appearing in output, example:

[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\videoio_registry.cpp (197) cv::`anonymous-namespace’::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(8, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930)
[ INFO:0] global C:\build\master_winpack-build-win6

I found a problem… the images are being stored in the following sequence:
0
1
11
12
.
.
.
19
2
21
22
what is changing the order of some frames. I guess that is due the string to be a vector, I am trying to fix it but I am not obtaining success.

std::vector<cv::String > f_BG;
glob(“C:/Users/Home/OneDrive/Desktop/video_make/plot_videoO6/*.png”, f_BG, true);
std::vector BG_images;
size_t count_BG = f_BG.size();

size_t n;
for (n = 0; n < count_BG; n++) {
    std::cout <<"\n" << f_BG[n];
}
system("pause");

that is due to the glob. the glob seems to give you a sorted list of files.

you can either name your files with leading zeros, which makes lexical order and numerical order identical… or you can run a loop through the numbers, generate the file name, and load each file from that (without the glob).

1 Like

Thank you! Now it is working perfect.
I did not know about this “trick” of leading zero. That help me to understand better the difference of glob and loop.