OpenCV VideoWriter does not open

时光怂恿深爱的人放手 提交于 2019-12-08 06:07:14

问题


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:

  1. Both Debug and Release OpenCV binaries.
  2. Copying opencv_ffmpeg248.dll to the executable's directory according to this.
  3. Passing exclusive codec codes such as CV_FOURCC('M','P','4','2') and others.
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!