Eliyahu-Shmuel Eliyahu-Shmuel - 3 months ago 11
C++ Question

Why the function 'x'.write(frame) isn't work for me?

When I use in the function: 'x'.write(frame) for write to video file in opencv the program pass the code and I compile it without Errors but when I open the file i see that it's 0 kb and the player can't play it. can someone help me?

Here my code:

// Setup output video
cv::VideoWriter output_cap("output.avi",
CV_CAP_PROP_FOURCC,
CV_CAP_PROP_FPS,
cv::Size(1376, 768));


// Loop to read frames from the image and write it to the output capture
cv::Mat frame = imread("1.jpg", 0);
for(int hgf=1;hgf<=300;hgf++)
{

if (!frame.data)
{
break;
}

output_cap.write(frame);

}

Answer

I changed my code to this and I changed my image to smaller image and it's work!

my code:

cv::Mat frame = imread("01.jpg",1);
VideoWriter output_cap("output.avi", CV_FOURCC('M', 'J', 'P', 'G'), 1,
frame.size(),true);

for (int hgf = 1; hgf <= 10; hgf++) {
output_cap.write(frame);
std::cout << "-";
}

the problem was that my image was 4608x3456 and the opencv cann't use in this file to create a video. I changed to 752x515 an this work!! good day!!!!!!