OpenCV VideoWriter无法打开文件

OpenCV VideoWriter does not open file

本文关键字:文件 VideoWriter OpenCV      更新时间:2023-10-16

以下代码无法打开VideoWriter对象:

#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
    VideoWriter oVideo;
    oVideo.open ("381.avi", -1, 30, Size(640,480), true);
    if (!oVideo.isOpened()) {
        cout  << "Could not open the output video for write" << endl;
        return -1;
    }
    return 0;
}

我在Ubuntu 12.04上运行Code::Blocks预构建的OpenCV 2.4.9。我已经在同一位置使用imwrite()编写了许多图像,没有问题,所以我怀疑它与权限有关。我还尝试了CV_FOURCC('X','V','I','D'),但没有工作。

我在这里错过了什么?

我重新安装了OpenCV使用这个惊人的脚本:https://help.ubuntu.com/community/OpenCV

解决。

确保您的机器安装了特定的编解码器

只是为了供任何在Windows的OpenCV 4.6中遇到类似问题的人参考,值得注意的是,预构建的opencv_world460。lib似乎不支持API之外的视频编解码器,我发现我需要在安装ffmpeg后重建和链接opencvbuildlibRelease文件夹中的所有单个库。