【问题标题】:problems reading output from ffmpeg从 ffmpeg 读取输出的问题
【发布时间】:2016-08-03 15:31:05
【问题描述】:

我正在尝试将原始 BGR24 图像数据从 ffmpeg 读取到 C++ 应用程序中。然后,C++ 应用程序将使用 openCV 进一步处理图像。 jpg -> ffmpeg -> 应用程序 -> openCV

我首先将 ffmpeg 的输出存储到一个文件中,然后从应用程序中读取该文件。 OpenCV 显然接受了这一点,因为它会愉快地显示图像。 但是,当将 ffmpeg 的输出直接传送到应用程序的标准输入时,它会失败。

我将程序更改为仅将输入保存到一个文件中,并比较了这两个文件。前 1856 个字节是相同的,但之后从标准输入保存的文件不同,之后整个文件只是十六进制 D1(或十进制 209)。

bytes read from stdin

bytes read from file

我认为我在读取 stdin 而不是具有不同输出的 ffmpeg 时犯了一个错误。但我觉得很奇怪,第一部分是一样的。 这是我用来读取标准输入的代码

char* img = (char*) malloc(FRM_SIZE_BYTES);
cout << "array address: " << &img;
cout << "array of size: " << FRM_SIZE_BYTES << endl;

int read = int read = read_stdin(img, FRM_SIZE_BYTES);
cout << "read " << read << " bytes" << endl;

int read_stdin(char* buffer, int count) 
{
    int read = 0;
    char in;
    for (int i = 0; i < count; i++) {
        cin >>  in;
        buffer[i] = in;
        read++;
    }
    return read;
}

这就是我尝试读取文件的方式

ifstream image;
image.open("img.raw", ios_base::binary | ios_base::in);
std::streampos start, end;  
char* imgFile = (char*)malloc(FRM_SIZE_BYTES);
image.read(imgFile, FRM_SIZE_BYTES);
image.close();

任何帮助将不胜感激

【问题讨论】:

  • 试试 unsigned char 而不是 char?
  • 我试过了,但没有任何作用

标签: c++ ffmpeg piping


【解决方案1】:

似乎问题在于读取标准输入。我在 Windows 机器上工作,并没有将输入流设置为二进制模式。

将输入流设置为二进制模式。

_setmode(_fileno(stdin), _O_BINARY);

并像这样读取流

cin.get(in);

修复了问题。

【讨论】:

    猜你喜欢
    • 2013-12-28
    • 1970-01-01
    • 2021-08-09
    • 2014-03-24
    • 2015-06-12
    • 2017-11-23
    • 2016-07-27
    • 2020-04-18
    • 2014-07-11
    相关资源
    最近更新 更多