加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在OpenCV中编写AVI文件

发布时间:2020-12-16 03:18:15 所属栏目:百科 来源:网络整理
导读:Learn OpenCv,Orielly中给出了网络和代码的例子. 经过多次尝试,out.avi文件被写入0个字节. 我不知道我哪里错了. 以下是我使用的代码 int main(int argc,char* argv[]) { CvCapture* input = cvCaptureFromFile(argv[1]); IplImage* image = cvRetrieveFrame(
Learn OpenCv,Orielly中给出了网络和代码的例子.

经过多次尝试,out.avi文件被写入0个字节.
我不知道我哪里错了.

以下是我使用的代码

int main(int argc,char* argv[]) {
    CvCapture* input = cvCaptureFromFile(argv[1]);
    IplImage* image = cvRetrieveFrame(input);

    if (!image) {
        printf("Unable to read input");
        return 0;
    }


    CvSize imgSize;
    imgSize.width = image->width;
    imgSize.height = image->height;



    double fps = cvGetCaptureProperty(
            input,CV_CAP_PROP_FPS
            );

    CvVideoWriter *writer = cvCreateVideoWriter(
            "out.avi",CV_FOURCC('M','J','P','G'),fps,imgSize
            );


    IplImage* colourImage;
    //Keep processing frames...
    for (;;) {

        //Get a frame from the input video.
        colourImage = cvQueryFrame(input);
        cvWriteFrame(writer,colourImage);

    }

    cvReleaseVideoWriter(&writer);
    cvReleaseCapture(&input);

}

解决方法

我打赌是cvCreateVideoWriter返回NULL.只是一步到位,看看是否真的.在这种情况下,问题可能是CV_FOURCC(..),它没有找到编解码器并强制返回0;

您可以尝试使用-1而不是CV_FOURCC.在运行期间会提示您选择适当的编解码器

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读