簡體   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