Creating Video from Images with OpenCV 2.4.1 on Ubuntu

后端 未结 3 975
旧巷少年郎
旧巷少年郎 2020-12-18 15:45

Here is my sample program for creating Video from images with OpenCV. But my output video is not working and An error occurred ans stating that \"Could not demultiplex strea

相关标签:
3条回答
  • 2020-12-18 15:52

    I'm also trying to create a video from multiple images. I didn't understand but are you trying to load a single image?

    IplImage* img = 0; img=cvLoadImage("IMG_0157.JPG");

    I was having some trouble with the video because I wasn't getting the width and height of the image(s) I was trying to load to create the video. So I first got those proprieties:

    IplImage *img = cvLoadImage("<folder>\\<image_name>.jpg");
    
    size.width = img->width;
    size.height = img->height;
    

    Then created the video writer and checked if it existed:

    CvVideoWriter *writer = cvCreateVideoWriter(
        "<video_name>.avi",
        -1,//CV_FOURCC('I','Y','U','V'), // VIDEO CODEC
        fps,
        size);
    
    if(writer == NULL)
        std::cout << "No videowrite here!" << '\nl';
    

    And for each image found wrote to the video's frame and then released it.

    while(img!=NULL)
    {
        sprintf( filename, "<folder>\\<image_name>_%d.jpg", i );
    
        img = cvLoadImage(filename); //imagem b&w
        cvWriteFrame(writer,img);
    
        i++;
    }
    
    cvReleaseVideoWriter(&writer);
    cvReleaseImage(&img);
    

    And it worked!

    Don't forget to initialize the variables filename and int i.

    Hope it helped!

    0 讨论(0)
  • 2020-12-18 16:06

    Usually this is not a FOURCC problem. The problem here is that the size of the img and the size used to open the VideoWriter are different.

    In that way you should be sure that IPLImages or Mat images, and the VideoWriter have the same size, otherwise the video output will be wrong.

    0 讨论(0)
  • 2020-12-18 16:10

    You can try a different FOURCC code. Some of them are not correctly supported by OpenCV, some by the multimedia apps. Having one that works with both OpenCV and your favourite video player is a matter of trial and error.

    What you can try: Use VLC (in case you don't alreay use it). It is one of the most robust players out there.

    If all you want to do is to display/process a sequence of images in OpenCV as video, you can use an undocumented feature of the VideoCapture: Load a sequence of images.

    The example is in C++, but you can easily convert it to C.

    // pics are a sequence of Pictures001.jpg, PicturesS002.jpg, etc
    cv::VideoCapture cap("path/to/my/Pictures%03d.jpg");
    
    cv::Mat frame;
    
    for(;;)
    {
        cap >> frame;
        if(frame.empty())
           break;
    
        // do some processing
    }
    
    0 讨论(0)
提交回复
热议问题