繁体   English   中英

在Android上的OpenGL中绘制视频帧

[英]Drawing Video Frames in OpenGL on Android

我目前正在使用一个通过Android上的OpenGL ES 1.0显示视频帧(作为位图)的系统。 我的问题是我无法获得超过10 fps的速度。

经过一些测试,我确定最大的瓶颈之一是需要使位图的宽度和高度均为2的幂。例如,640x480视频必须缩放为1024x1024。 没有缩放比例,我已经能够获得约40-50fps的速度,但是纹理只是显示为白色,这对我没有好处。

我知道OpenGL ES 2.0支持使用两个纹理的非幂,但是我没有使用着色器/2.0中的其他新功能的经验

有什么办法可以解决这个问题? 与我现有的相比,其他视频播放如何获得如此出色的表现? 我已包含一些代码以供参考。

private Bitmap makePowerOfTwo(Bitmap bitmap)
{
    // If one of the bitmap's resolutions is not a power of two
    if(!isPowerOfTwo(bitmap.getWidth()) || !isPowerOfTwo(bitmap.getHeight()))
    {
        int newWidth = nextPowerOfTwo(bitmap.getWidth());
        int newHeight = nextPowerOfTwo(bitmap.getHeight());

        // Generate a new bitmap which has the needed padding
        return Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true);
    }
    else
    {
        return bitmap;
    }
}

private static boolean isPowerOfTwo(int num)
{
    // Check if a bitwise and of the number and itself minus one is zero
    return (num & (num - 1)) == 0;
}

private static int nextPowerOfTwo(int num)
{
    if(num <= 0)
    {
        return 0;
    }

    int nextPowerOfTwo = 1;

    while(nextPowerOfTwo < num)
    {
        nextPowerOfTwo <<= 1; // Bitwise shift left one bit
    }

    return nextPowerOfTwo;
}

仅仅因为纹理必须是2的幂,并不意味着您的数据必须是2的幂。

您可以在使用glTexImage初始化的过程中自由创建1024x1024(或1024x512)纹理,使用glTexSubImage用位图数据填充较低的640x480,然后使用一些智能texcoords (0,0) to (640/1024, 480/1024) 其余的纹理将包含从未见过的空白空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM