问题
Running Windows 7, x64 with OpenCV 2.4.8 (pre-built binaries).
Trying the following basic code:
VideoWriter wrt;
wrt.open("video.mp4", -1, 29, Size(480, 640));
This does nothing. The expected popup for codec selection does not open, nor is the writer getting open (i.e. a call to wrt.isOpen()
returns false). Also, the internal pointer inside the writer class wrt.writer
remains null.
Tried:
- Both Debug and Release OpenCV binaries.
- Copying
opencv_ffmpeg248.dll
to the executable's directory according to this. - Passing exclusive codec codes such as
CV_FOURCC('M','P','4','2')
and others. - Hitting the computer.
Nothing worked. Any help/direction would be appreciated..
回答1:
Try
VideoWriter wrt;
wrt.open("video.avi", -1, 29, Size(480, 640));
回答2:
VideoCapture cap;
VideoWriter videoWriter;
cap.open(0);
if (!cap.isOpened())
{
printf("can not open camera or video file\n");
return ;
}
string namemove("foo.AVI");
int fourCC = CV_FOURCC('M', 'J', 'P', 'G');
Size S = Size((int)cap.get(CAP_PROP_FRAME_WIDTH), (int)cap.get(CAP_PROP_FRAME_HEIGHT));
int fps = cap.get(CAP_PROP_FPS);
videoWriter.open(namemove, -1, cap.get(CAP_PROP_FPS), S, true);
if (!videoWriter.isOpened())
{
cerr << "Cannot open output file " << endl;
return ;
}
Mat img0;
namedWindow("image", WINDOW_NORMAL);
for (;;)
{
cap >> img0;
if (img0.empty())
break;
videoWriter << img0;
imshow("image", img0);
char k = (char)waitKey(30);
if (k == 27) break;
}
来源:https://stackoverflow.com/questions/21682925/opencv-videowriter-does-not-open