【问题标题】:problem in loading texture from AVFrame(android)从 AVFrame(android) 加载纹理的问题
【发布时间】:2011-08-01 22:50:50
【问题描述】:

在将数据从 AVFrame 加载到 openGL 时遇到问题:

 int target_width = 320;
                int target_height = 240;
                img_convert_ctx = sws_getContext(pCodecCtx->width, pCodecCtx->height,
                                           pCodecCtx->pix_fmt,
                                           target_width, target_height, PIX_FMT_RGBA, SWS_FAST_BILINEAR,
                                           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);
                //free(data);
                int line=target_width*target_height*4;
                data=(char*)malloc(line);
                if (!data)
                    LOGE("create data frame fail");
                LOGE("successful data");
                filldata(data,pFrameRGB,target_width,target_height);

函数filldata为:

    static void filldata(char *data,AVFrame *pFrame,int w,int h)
{uint8_t *frameLine;
    int  yy;
    int i=0;

for (yy = 0; yy < h; yy++) {

frameLine = (uint8_t *)pFrame->data[0] + (yy * pFrame->linesize[0]);

int xx;

for (xx = 0; xx < w; xx++) {
            int in_offset = xx * 4;

data[i++] = frameLine[in_offset];

data[i++] = frameLine[in_offset+1];

data[i++] = frameLine[in_offset+2];

data[i++] = frameLine[in_offset+3];
        }
    }
}

之后我使用数据传输到

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, *wi, *he, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)data);

但它不能显示纹理,可能上面的数据和函数 gltextimage2D 中的数据不同。 请帮我弄清楚 gltextimage2D 的格式是什么,以便我可以配置数据以显示纹理。或者任何人都有一些示例代码给我看。

【问题讨论】:

    标签: android opengl-es ffmpeg android-ndk


    【解决方案1】:

    我不清楚,但您可以尝试使用我在视频播放器应用中使用的richq glbuffer。它对我有用,而且帧速率也更好。

    试一试,祝你好运。

    【讨论】:

      【解决方案2】:

      Word 规定,在为 sws_getContext() 指定宽度和高度时,您应该使用 2 次方维度。如果这不能解决您的问题,Android007 指出的参考是一个很好的参考,但您可能还想看看https://code.google.com/p/android-native-egl-example/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2010-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-10-12
        • 2014-11-22
        相关资源
        最近更新 更多