I coded the below which tries to hold a picture and count number hundred and finally grab all them to a video with following codec MP42(MPEG4-V2)
#include <stdAfx.h>
#include <iostream>
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int n=0;
char a;
int main(int, char** argv)
{
Mat image= imread("C:\\Users\\Metin\\Desktop\\images.jpg");
Mat newimage;
VideoWriter vide ("Hopdedik.avi",CV_FOURCC('M','P','4','2'),30.0,image.size());
vide.open("Hopdedik.avi",CV_FOURCC('M','P','4','2'),30.0,image.size());
for(int n=0; n<100;n++){
cout<<n<<'\n';
std::string s= to_string(static_cast<long long>(n));
image.copyTo(newimage);
putText(newimage,s,Point(100,40),cv::FONT_HERSHEY_COMPLEX,2,cv::COLORMAP_COOL,2,2,false);
imshow("asd",newimage);
if(!vide.isOpened())cout<<"can not opened";
vide.write(newimage);
waitKey(10);
}
vide.release();
return 0;
}
I started debugging on Release mode and copied the .exe files to Virtualbox Win7-64 bit. Right after I put necessary .dll files exe works but the code can't properly create the video.
I have tried to install following two codecs: http://www.fourcc.org/downloads/angel-potion-mpeg-4--8/ and Indeo which is: http://www.afreecodec.com/codec-by-code/iv45-160.html
But it did not work.
Once I faced a similar problem where opencv couldn't read a video. There was no warning at all. The reason was that an automated string maker resulted in "opencv_mmpeg.dll" which was missing from the system. So, I debugged up to cap_ffmpeg.cpp and found this:
So, copy opencv_ffmpeg_64.dll to your folder and you might have some results. Else, you need to debug deeply. Start by inserting into your project the file opencv/modules/highgui/src/cap.cpp (and the headers needed to be compiled) so you can debug line by line. I suppose many other files will be needed to go further down into the code.