C++ 从原始图像写入AVI文件

C++ 从原始图像写入AVI文件,c++,opencv,C++,Opencv,我正在读取一个只有1和0的原始文件,该文件已从SurfaceFlinger保存到字符缓冲区并写入IplImage。然后我尝试将其写入视频文件,但cvWriteFrame返回0。有人能帮我解决问题吗 下面是我的代码 #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> #include <stdio.h> #include

我正在读取一个只有1和0的原始文件,该文件已从SurfaceFlinger保存到字符缓冲区并写入IplImage。然后我尝试将其写入视频文件,但cvWriteFrame返回0。有人能帮我解决问题吗

下面是我的代码

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <stdio.h>
#include <cstring>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
    FILE * pFile;
    long lSize;
    char * buffer;
    size_t result;

    pFile = fopen(argv[1], "rb");
    if (pFile == NULL) {
        fputs("File error", stderr);
        exit(1);
    }

    // obtain file size:
    fseek(pFile, 0, SEEK_END);
    lSize = ftell(pFile)
    rewind(pFile);

    // allocate memory to contain the whole file:
    buffer = (char*) malloc(sizeof(char) * lSize);

    if (buffer == NULL) {
        fputs("Memory error", stderr);
        exit(2);
    }

    // copy the file into the buffer:
    result = fread(buffer, 1, lSize, pFile);
    if (result != lSize) {
        fputs("Reading error", stderr);
        exit(3);
    }

    // clean up
    fclose(pFile);


    IplImage *img;
    img = cvCreateImage(cvSize(768, 1280), IPL_DEPTH_8U, 4);
    memcpy(img->imageData, buffer, lSize);
    cvSaveImage("Displaywindow.png", img);

    int width = img->width;
    int height = img->height;

    CvVideoWriter *writer = cvCreateVideoWriter("out.avi",
                                    CV_FOURCC_DEFAULT,
                                      30,
                                       cvSize(height, width), 1);

    if(writer == NULL)
    {
        printf("error\n");
        exit(0);
    }
    for(int counter=0;counter < 3000;counter++)
    {
        if(cvWriteFrame(writer,img) == 0)
        {
            printf("con't write\n");
            exit(0);
        }
    }
    waitKey(0);
    return 0;
}
我正在传递我的原始文件作为参数