c++ - 使用 videowriter opencv 的视频大小为 0 字节

标签 c++ opencv video

我面临的问题是,当我尝试使用 Videowriter 保存图像时,它会创建视频文件,但大小为 0。我创建了一个 header ,声明了一个保存视频的函数和一个单独的 .cpp 文件定义函数。当我只将整个代码写在一个文件中而不是像以前那样在单独的文件中时,包括 ViceoCapture 和 VideoWriter,它运行良好,甚至以适当的文件大小保存视频文件。

当我开始调试时,我发现每次我收到一个帧但 VideoWriter.open 为空或它说没有为 opencv_highgui.dll 加载符号

**savevideo.cpp file**
#include"SaveVideo.h"


int CSaveVideo::savevideo()//string InpVideo, int pinstatus)
{
    VideoCapture oVcam(0);


    Mat vFrame;
    string OutPath = "C:\\Users\\20080031\\Desktop\\";
    string Filename = "Vout.avi";
    int vfourcc = CV_FOURCC('M', 'J', 'P', 'G');
    int vfps = 20;
    VideoWriter oVWrite;
    oVWrite.open(Filename, vfourcc, vfps, Size(480, 640), true);

    if (!oVcam.isOpened())
    {
        cout << "Camera not opened" << endl;
    }
    while (1)
    {
        oVcam.read(vFrame);
        imshow("Input", vFrame);
        waitKey(1);
        oVWrite.write(vFrame);

    }



}
CSaveVideo::CSaveVideo()
{
    cout << "Inside Constructor" << endl;
}
CSaveVideo::~CSaveVideo()
{
    //VideoCapture Vcam0;
    cout << "Inside Distructor" << endl;
    //Vcam0.release();
}
 **saveVideo.h**
#ifndef SAVEVIDEO_H
#define SAVEVIDEO_H

#include<iostream>
#include<stdio.h>
#include<string>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<opencv2/core/core.hpp>
#include <opencv2\opencv.hpp>



using namespace std;
using namespace cv;


class CSaveVideo
{
public:
    CSaveVideo();
    ~CSaveVideo();

    //string m_sGPIOpinstatus;
    //char m_cSTOP;

    int savevideo();//string PinStatus, char End,  );
};
#endif SAVEVIDEO_H
**main.cpp**
#include"SaveVideo.h"


int main()
{
    CSaveVideo save;
    save.savevideo();
    /*cout << out<<endl;*/
    return 0;
}

最佳答案

最好使用这种格式-

VideoWriter oVidWrite;
int nframe_width = oVidCap.get(CV_CAP_PROP_FRAME_WIDTH);
int nframe_height = oVidCap.get(CV_CAP_PROP_FRAME_HEIGHT);
string str_Path = "video.avi";
int fps = 30;

oVidWrite.open(str_Path, CV_FOURCC('M', 'J', 'P', 'G'), fps, Size(nframe_width, nframe_height), true);

关于c++ - 使用 videowriter opencv 的视频大小为 0 字节,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36930344/

相关文章:

java - 为什么编译器不使用断言来优化?

image - 从点获取畸变变换

iphone - 带有 iPhone 图像框架的 HTML5 视频

ios5 - AVPlayer:按下主页按钮时背景音频停止,但在锁定屏幕时播放

python-3.x - 我将如何使用 ffpyplayer 播放视频流?

c++ - 如何在执行 ./configure 时设置 ccshared=-fPIC?

c++ - 将 QString 从父 QT 传递给子 QT

c++ - 整数作为 8 传递给函数,但函数内部的值是 -439854520

c++ - OpenCV如何表示具有2个两个值的线?

opencv - opencv detectmultiscale3 中 levelweights 的取值范围是多少?