I am writing YUV (YV12) frames to YUV file. I am saving exactly 101 frames.But when I am playing the output YUV file I have 2x more frames whereas each second frame is always empty.
Here is my code:
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);
I run this block 101 times.I double checked it.Where does another frame come from ?
Don't know anything about opengl but the size of a frame in YV12-format is
width * height * 1.5
i.e. the croma-part is sub-sampled by a factor 2 horizontally and vertically.
Above I see 3
a lot, change that value to 1.5
instead.
If you're interested in a YUV-format conversion tool checkout this which I wrote in python. And a viewer based on SDL here. Lot's of inspiration there :-)