About render the NV12 format
yuace opened this issue · 1 comments
yuace commented
void GL_VideoRenderer::update_texture_nv12(AVFrame* frame) {
assert(frame);
assert(frame->format==AV_PIX_FMT_NV12);
if(nv12_frametexture.textures[0]==0){
std::cout<<"Creating nv12 textures\n";
glGenTextures(2, nv12_frametexture.textures);
}
int videoWidth = frame->width;
int videoHeight = frame->height;
int size = av_image_get_buffer_size((enum AVPixelFormat)frame->format, frame->width,frame->height, 1);
static uint8_t * out_buffer = (uint8_t*)av_malloc(size);
av_image_copy_to_buffer(out_buffer, size,
(const uint8_t * const *)frame->data,
(const int *)frame->linesize, (enum AVPixelFormat)frame->format,
frame->width, frame->height, 1);
for(int i=0;i<2;i++){
glBindTexture(GL_TEXTURE_2D,nv12_frametexture.textures[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, frame->width,frame->height>>i, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, out_buffer+videoWidth*videoHeight*i);
glBindTexture(GL_TEXTURE_2D,0);
}
nv12_frametexture.has_valid_image= true;
av_frame_free(&frame);
}
I decode the format is nv12, so I refer to the cuda. But the display seems like just have the Y, the uv is not correct.Could u give some advice about it?
yuace commented
have submit the issue