如何AVFrame转换为通过glTexImage2D的纹理? [英] how to convert AVFrame to texture used by glTexImage2D?
问题描述
你知道AVFrame有2个属性:pFrame->数据,pFrame-> LINESIZE。之后,我读视频/sdcard/test.mp4(Android平台)框架,并转换为RGB AVFrame副:
as you know that AVFrame has 2 property:pFrame->data, pFrame->linesize. After i read frame from video /sdcard/test.mp4 (android platform), and convert to RGB AVFrame vice:
img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
pCodecCtx->pix_fmt,
target_width, target_height, PIX_FMT_RGB24, SWS_BICUBIC,
NULL, NULL, NULL);
if(img_convert_ctx == NULL) {
LOGE("could not initialize conversion context\n");
return;
}
sws_scale(img_convert_ctx, (const uint8_t* const*)pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);
我转换后得到pFrameRGB中。我需要使用glTextImage2D到纹理它在OpenGL:
I get pFrameRGB after converted. I need to texture it in opengl by using glTextImage2D:
// Create The Texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
//我不知道这里的数据pFrameRGB->数据或没有,如果没有,如何将它转换为approriate格式glTextImage这样我就可以在OpenGL中显示视频,使用AVFrame和gltextImage2D。一切都有助于从u非常AP preciated。
// i don't know data in here is pFrameRGB->data or not,if not, how to convert it to approriate format for glTextImage so i can display video in opengl, using AVFrame and gltextImage2D. All helps from u are very appreciated.
推荐答案
两件事情:(1)是2 TARGET_WIDTH和TARGET_HEIGHT权力?如果没有,你会得到一个空白屏幕。您需要将画面比例为2的(2)它说:数据,在glTexImage,你需要使用pFrameRGB->电力数据[0]作为基兰指出。
Two things: (1) is target_width and target_height powers of 2? If not, you'll get a blank screen. You need to scale the picture to a power of 2. (2) where it says "data" in glTexImage, you need to use pFrameRGB->data[0] as Kieran pointed out.
还有一件事,你并不需要使用RGBA(除非它的速度更快,我还没有测试出来)。如果你这样做,你改变了ffmpeg的目标格式PIX_FMT_RGBA然后更改GL_RGB的两个实例来GL_RGBA。
One more thing, you don't need to use RGBA (unless it's faster. I haven't tested it out). If you do, you change the ffmpeg target format to PIX_FMT_RGBA and then change both instances of GL_RGB to GL_RGBA.
除此之外,我看不出有什么毛病的code。我几乎完全一样的code和它运行得很好。
Other than that, I don't see anything wrong with your code. I have almost the same exact code and it runs just fine.
这篇关于如何AVFrame转换为通过glTexImage2D的纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!