openCV cvCreateVideoWriter始终返回null [英] openCV cvCreateVideoWriter always returns null

查看:366
本文介绍了openCV cvCreateVideoWriter始终返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Mandriva Linux 2009.1下使用openCV保存视频文件. 不幸的是,尽管我可以看到并修改mpeg字段,但是cvCreateVideoWriter始终返回null,换句话说,cvCaptureFromCam,cvCaptureFromAvi,cvRetrieveFrame可以正常工作.

我尝试了页面.我还尝试将0表示未压缩的avi,将-1表示为fourcc参数中的选择框,但是没有弹出选择,什么也没发生.我也将isColor修改为0.

我在工作目录中也具有写权限.

这是相关的代码段:

    CvVideoWriter *writer = 0;
    int isColor = 1;
    int fps = 25;
    int frameW = 640;
    int frameH = 480;


    if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
        capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
    else if( argc == 2 ) {
        printf("argc == 2 :%s:\n", argv[1] );
        capture = cvCaptureFromFile( argv[1] );
    }

    cvInitSystem(argc,argv);

 writer = cvCreateVideoWriter("out.avi",CV_FOURCC('I','Y','U','V'),fps,cvSize(frameW,frameH),isColor);

可能是什么问题?

解决方案

我阅读了您的帖子,Lance的回复和您对它的评论,然后终于找到适合自己的解决方法,并决定为每个在此问题上苦苦挣扎的人添加一些笔记. /p>

首先要检查的是CMake是否已使用FFmpeg构建了OpenCV.我执行此操作的快速而可怕的方法就是再次使用标志和参数运行cmake,就像您在安装过程中写的一样.在输出的末尾将有关于将安装哪些组件的日志.如果您的参数复制了实际安装期间使用的参数,则将获得有关已已安装的内容的信息.

接下来,您可能需要检查Linux系统上可用的编码器和解码器中的编解码器.我通过使用ffmpeg -codecs来做到这一点.

第三记可靠且为cvCreateVideoWriter设置了原始参数:

"a0000.png",0,fps,大小,0

fpssize是分别包含fps和frame_size字段值的变量.您将获得大量图像-Lance Richardson和rics已经注意到.

最后,对于使用FFmpeg构建OpenCV并安装XVID编码器的系统,我将这些参数插入cvCreateVideoWriter:

"/home/me/openCVOut/a.avi",CV_FOURCC('X','V','I','D'),fps,大小

最后得到我想要的.

希望我的回答有一定用处!

I am trying to save a video file with openCV under Mandriva Linux 2009.1. Unfortunately cvCreateVideoWriter always returns null although I could see and modify both and mpeg fiels, in other words cvCaptureFromCam, cvCaptureFromAvi, cvRetrieveFrame is working.

I tried all the possible codecs from this tutorial and this codec page. I also tried 0 for uncompressed avi and -1 for a selection box in the fourcc parameter, but no choice has popped up and nothing happened. I also modified isColor to 0.

I also have write permissions in the working directory.

Here is the relevant code snippet:

    CvVideoWriter *writer = 0;
    int isColor = 1;
    int fps = 25;
    int frameW = 640;
    int frameH = 480;


    if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
        capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
    else if( argc == 2 ) {
        printf("argc == 2 :%s:\n", argv[1] );
        capture = cvCaptureFromFile( argv[1] );
    }

    cvInitSystem(argc,argv);

 writer = cvCreateVideoWriter("out.avi",CV_FOURCC('I','Y','U','V'),fps,cvSize(frameW,frameH),isColor);

What could be the problem?

解决方案

I read your post, Lance's reply and your comments to it, then finally found workaround for myself and decided to add some notes for everyone struggling with that issue.

First thing to check is whether CMake has built OpenCV with FFmpeg. My fast and horrible way to do this is just to run cmake with flags and parameters, as you wrote them during installation, again. In the end of output there will be logs about which components will be installed. If your parameters copy those used during the actual installation, you'll get info about what is already installed.

Next you may want to check available encoders and decoders for codecs on your linux system. I do this by using ffmpeg -codecs.

Third note is reliable and primitive arguments set for cvCreateVideoWriter:

"a0000.png", 0, fps, size, 0

fps and size here are variables containing your values for fps and frame_size fields respectively. You'll get bags of images -- what Lance Richardson and rics already noted.

Finally, for my system, on which OpenCV is built with FFmpeg and XVID encoder is installed, I plug these arguments into cvCreateVideoWriter:

"/home/me/openCVOut/a.avi", CV_FOURCC('X','V','I','D'), fps, size

and finally get what I want.

Hope my answer is of some use!

这篇关于openCV cvCreateVideoWriter始终返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆