c++ - Opencv VideoWriter 只保存一帧

标签 c++ opencv

我正在尝试从两张图片创建 1fps webm, 代码:

    // path to output
    string outputVideoPath = "/home/gio/Desktop/giffer/def.webm";
    // write dimensions in size struct
    Size dims = Size(640,480);

    // create and open VideoWriter object
    VideoWriter outputVideo;
    outputVideo.open(outputVideoPath, CV_FOURCC('V','P','8', '0'), 1, dims, true);

    // check if opened
    if(!outputVideo.isOpened()){
        cout << "Creating outputVideo fail" << endl;
        return -1;
    }

    // I hate strings
    string paths[2];
    paths[0] = "/home/gio/Desktop/giffer/images_temp/g0.jpg";
    paths[1] = "/home/gio/Desktop/giffer/images_temp/g1.jpg";

    for (int i = 0; i < 2; i++) {
        cout << paths[i] << endl;
        Mat temp = imread(paths[i]);
        outputVideo.write(temp);
        usleep(10000);
    }

结果是唯一的一帧(最后一张图像),长 1 秒。 我做错了什么?

编辑: 我尝试了 .avi 扩展,DIVX 编解码器,它工作正常。有什么想法可以让它在 .webm 上运行吗?或 .gif

最佳答案

应该是

usleep(1000000);

由于 usleep 参数以微秒为单位给出,因为您 can read here .

关于c++ - Opencv VideoWriter 只保存一帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33858283/

相关文章:

c++ - 如何在vc++中获取网络连接电脑的IP地址

opencv - 如何使用 ffmpeg 交叉编译 OpenCV

android - 支持 Android 的硬 float 的 OpenCV

c++ - 获取左下角和左上角

image - 如何检测垂直线和水平线?

c++ - CFolderDialog 设置状态文本

c++ - 我可以只为某些特化定义静态 constexpr 数据成员吗?

c++ - 锁()的实现

c++ - 什么是旧式类型转换 : pv = (void*)ps; 的命名类型转换

python - 如何在 numpy 中创建递增的多维数组