Ask Your Question

Revision history [back]

Creating Video From Images In C

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;
   }