Why is the 'x'.write (frame) function not working for me?

When I use the function: "x'.write (frame) to write to a video file in opencv, the program passes the code, and I compile it without errors, but when I open the file, I see that it is 0 kb and the player cannot play it Can anyone help me?

Here is 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);

    }

Good day to all!

+4
source share
2 answers

I changed my code to this and I changed the image to a smaller image and it works!

my code is:

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 opencv couldn’t use it in this file to create the video. I changed this job to 752x515! a good day!!!!!!

+2
source

, , FOURCC VideoWriter. CV_CAP_PROP_FOURCC (#defined as 6) , FOURCC, . CV_CAP_PROP_FPS (#defined as 5), VideoWriter 5,0 .

:

#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    if ( argc != 2 ) {
        cout << "image required" << endl;
        return -1;
    }
    Mat frame = imread(argv[1], 1);

    VideoWriter output_cap("output.avi", CV_FOURCC('M','J','P','G'), 15,
        frame.size());

    for(int hgf=1; hgf<=300; hgf++) {
        output_cap.write(frame);
    }

    return 0;
}

. Linux VideoWriter , . M-JPEG ( ) H.264, M-JPEG OpenCV 2.4, 3.X H.264 , 2.4 3.X.

+2

Source: https://habr.com/ru/post/1651092/


All Articles