将YUV写入文件会导致重复的帧
Writing YUV to file results in duplicated frames
我正在将YUV (YV12)帧写入YUV文件。我正好保存了101帧。但是当我播放输出YUV文件时,我有2倍多的帧,而每一帧总是空的。
下面是我的代码: size_t lenght=_viewWidth * _viewHeight * 3;
BYTE *bytes=(BYTE*)malloc(lenght);
/////////////// read pixels from tex /////////////////////
glBindTexture(GL_TEXTURE_2D,tex);
glGetTexImage(GL_TEXTURE_2D,0,GL_RGB,GL_UNSIGNED_BYTE,bytes);
glBindTexture(GL_TEXTURE_2D,0);
BYTE *uvOut= new uint8_t[_viewWidth * _viewHeight *3];
if(cfg.seqStart <= cfg.seqEnd)
{
hOutFile = fopen( outFileName.c_str(), cfg.appendMode ? "ab" : "wb" );
assert(hOutFile!=0);
RGBtoYUV420PSameSize(bytes,uvOut,3,0,_viewWidth,_viewHeight);
fwrite(uvOut,_viewWidth* 3, _viewHeight, hOutFile); // Write V line
fclose(hOutFile);
cfg.seqStart++;
}else{
printf("done");
}
delete uvOut;
free(bytes);
我运行这个块101次。我又检查了一遍。另一个框架从何而来?
我对opengl一无所知,但是yv12格式的帧的大小是
width * height * 1.5
。色度部分在水平和垂直方向上被2倍的采样。上面我经常看到3
,将该值改为1.5
。
如果您对yuv格式转换工具感兴趣,请检查我用python编写的这个。还有一个基于SDL的查看器。这里有很多灵感:-)
相关文章:
- .cpp和.h文件中的模板专用化声明
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 文本文件中的单词链表
- CMake-按正确顺序将项目与C运行时对象文件链接
- 使用新行和不使用新行读取文件
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 挂起和取消挂起一个文件DLL
- 如何确定我已使用非编码文件到达 EOF?
- 命名空间中具有.h和.cpp文件的类
- 如何使用ndk-build.cmd构建Android.so文件
- 从包含m行的文件中提取n行,必要时(惰性地)重复该文件
- 读取文件并输入到矢量中
- 在C++中查找文件
- c++库的公共头文件中应该包含什么
- 用c++从输入文件中读取另一行
- Cppcheck生成xml转储文件
- 读取文件的最后一行并输入到链接列表时出错
- 无法编译 rtmidi 测试 cmidiin.cpp 文件, 非法指令
- 2个YUV文件的PSNR计算器使用c++分割错误
- 将YUV写入文件会导致重复的帧