Creating Video From Images In C [closed]

asked 2020-06-29 05:22:31 -0600

tomer gravatar image

Hi! I want to create a video from images (I have linked that contains paths to images), but I need to do it only in C (and not in CPP).

But the problem is that after the video is created I can't open it since windows show an error that the file is corrupted and cannot be showed...

This is what I did:

    void saveToVideo(FrameNode* headNode)
    {
         CvVideoWriter* videoW = NULL;
         videoW = cvCreateVideoWriter("C:\\Users\\Tomer\\Desktop\\hello.avi", CV_FOURCC('M', 'P', 'E', 'G'), 10, cvSize(500, 500), true); // creating video writer
         FrameNode* currentNode = headNode;
            IplImage* image = 0;
        int i = 0;
        bool returnValue = false;
        printf("videoW Created!");
        if (videoW)
        {
                  for (i = 0; i < REPEAT_VIDEO; i++)
          {
            while (currentNode != NULL) // writing the whole list
                {
                 image = cvLoadImage(currentNode->frame->path, CV_LOAD_IMAGE_COLOR);
                  cvWriteFrame(videoW, image);
                  cvReleaseImage(&image);
                  currentNode = currentNode->next;
            }
            currentNode = headNode; // writing the video 5 times
         }
         cvReleaseVideoWriter(&videoW);
         returnValue = true;
      }

      return returnValue;
   }
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by berak
close date 2020-06-29 05:49:27.364599

Comments

1

opencv's C-api is DEAD, you MUST NOT use it, you will HAVE TO use c++, cv::Mat, cv::VideoWriter, etc.

berak gravatar imageberak ( 2020-06-29 05:50:49 -0600 )edit

apart from that, there might be 2 possible reasons:

  • the image size you try to write did not match the one in the VideoWriter
  • it did not find opencv_ffmpeg.dll at runtime on the PATH
berak gravatar imageberak ( 2020-06-29 06:21:06 -0600 )edit