2012-02-17 55 views
3

我一直試圖在我的iOS應用程序中實施ffmpeg幾周。現在我可以播放幾個AVI文件,但其他文件,如flv,wma,mp4 ...播放速度很慢。替代ffmpeg的iOS

我花了很多時間與ffmpeg和opengl,我沒有找到解決方案。

我正在尋找其他替代品來播放ios設備上的文件。

有人知道我可以用來播放這些文件的其他庫,框架......。不管他們是否有營業執照。

非常感謝,

編輯:

初始化着色器:

shader = [[GLShader alloc] initWithFileName:@"render" attributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                          [NSNumber numberWithInt:0], @"position", 
                          [NSNumber numberWithInt:1], @"texCoords", nil] 
             uniforms:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0], @"sampler0", 
                          [NSNumber numberWithInt:0], @"viewProjectionMatrix",nil]]; 

render.fsv:

uniform sampler2D sampler0; 
varying highp vec2 _texcoord; 
void main() 
{ gl_FragColor = texture2D(sampler0, _texcoord);} 

render.vsf:

attribute vec4 position; 
attribute vec2 texCoords; 
varying vec4 colorVarying; 
varying vec2 _texcoord; 
uniform mat4 viewProjectionMatrix; 

void main() 
{ _texcoord = texCoords; 
gl_Position = viewProjectionMatrix * position;} 

如何在此代碼中實現您的解決方案?

+1

請小心 - _9.1不使用MediaPlayer框架訪問音樂庫中媒體的應用程序將被拒絕_ – beryllium 2012-02-17 15:45:08

+0

那麼,如果它是AVI或WMA,可疑的是它在音樂庫中...... – StilesCrisis 2012-02-17 16:51:14

回答

3

我遇到過類似的問題。有兩個瓶頸:

  1. 解碼從YUV
  2. 轉換爲rgb格式

我通過使用着色器轉換圖像解決的第二個問題。它現在非常快速(我可以在iPad2上以30 fps的速度同時渲染6個視頻)。

這裏是片段着色器的一部分:

uniform sampler2D y; 
    uniform sampler2D u; 
    uniform sampler2D v; 

    ... 
    y = texture2D(y, vec2(nx,ny)).r; 
    u = texture2D(u, vec2(nx, ny)).r - 0.5; 
    v = texture2D(v, vec2(nx, ny)).r - 0.5; 

    r = y + 1.13983*v; 
    g = y - 0.39465*u - 0.58060*v; 
    b = y + 2.03211*u; 

    gl_FragColor = vec4(r, g, b, 1.0); 

注意:您可以選擇存儲Y,U,V在3層不同的紋理部件。

nx和ny - 是歸一化的紋理座標(從0到1紋理)。

+0

Hi max very感謝您的回答。我真的很高興你的答案。我對opengl和着色器沒有太多的想法。 你知道任何一個例子嗎? – 2012-02-18 12:14:39

+0

這真的不是太複雜。您只需使用採樣器獲取像素顏色,然後使用簡單的you-rgb轉換公式轉換它。你可以在維基百科上找到它:http://en.wikipedia.org/wiki/YUV#Conversion_to.2Ffrom_RGB – Max 2012-02-18 14:34:46

+0

您好,我不知道在哪裏可以添加此代碼。在我的渲染方法中,我得到了uint8_t格式的幀緩衝區。我用這種方法編輯帖子。非常感謝您的幫助。 – 2012-02-22 06:39:15