小编Doc*_*Doc的帖子

iOS - 如何使用openGL绘制YUV图像

目前,我正在尝试使用openGL绘制图像(图像经常更新,因此必须重新绘制).以前,我将我的图像从YUV转换为RGB,然后使用这个新图像用openGL绘制.一切正常,但转换过程并不是特别快.

我现在正在尝试更改代码,以便在openGL着色器中处理转换.环顾四周后,我发现了一些代码片段(特别是着色器和我的renderImage函数的大部分),这些代码片段帮助我获得了基线,但我似乎无法真正得到正确绘制的图像 - 所有我曾经看是一个黑色的图像.

我很可能错过了一些非常简单和重要的东西 - 我对openGL的体验相当有限.如果有人可以看看,看看他们是否认识到任何错误,请告诉我.

我应该指出,我正在尝试支持iOS 4.x,因此CVOpenGLESTextureCacheCreateTextureFromImage不应该可用(即使我想要,我也不是很积极如何设置使用它).

任何帮助,将不胜感激.代码如下 -

我的顶点着色器:

attribute vec4 position;
attribute vec4 inputTextureCoordinate;

varying vec2 textureCoordinate;

void main()
{
    gl_Position = position;
    textureCoordinate = inputTextureCoordinate.xy;
}
Run Code Online (Sandbox Code Playgroud)

片段着色器:

#ifdef GL_ES
precision mediump float;
#endif

varying vec2 textureCoordinate;

uniform sampler2D videoFrame;
uniform sampler2D videoFrameUV;

const mat3 yuv2rgb = mat3(
                          1, 0, 1.2802,
                          1, -0.214821, -0.380589,
                          1, 2.127982, 0
                          );

void main() {
    vec3 yuv = vec3(
                    1.1643 * (texture2D(videoFrame, textureCoordinate).r - 0.0625),
                    texture2D(videoFrameUV, textureCoordinate).r - 0.5,
                    texture2D(videoFrameUV, …
Run Code Online (Sandbox Code Playgroud)

opengl-es yuv ios

14
推荐指数
1
解决办法
2万
查看次数

AVAudioSession中断

所以在我的应用程序中,在iOS 6上运行,一切似乎都可以正常使用音频.我使用旧的C API格式来捕获使用回调的中断; 通过设置:AudioSessionInitialize(NULL, NULL, interruptionListenerCallback, (__bridge void *)self)它很棒.但是,使用iOS 7 SDK时,似乎在设备接到呼叫或闹钟响起时,我的中断回调永远不会被调用.

经过一番环顾,我听说旧的C api已被弃用,你应该转向更新的AVAudioSession功能.更多阅读显示AVAudioSession委托已被弃用,您应该使用NSNotificationfor AVAudioSessionInterruptionNotification来捕获中断并做任何需要完成的事情.

对我来说,似乎这个通知从未被实际触发,因此我从未得到适当的中断,然后在通话结束后打破了我的所有音频内容.

我这样注册通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(AudioInterruption:) name:AVAudioSessionInterruptionNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

现在,该AudioInterruption:函数只是记录它被触发了.日志和任何断点都没有触发.

要清楚,最初音频播放和录制工作正常.发生中断时(例如来电或闹钟),不会触发中断通知.如果需要更多周围代码,请告诉我.

audio interruption ios avaudiosession

12
推荐指数
1
解决办法
9891
查看次数

CVOpenGLESTextureCacheCreateTextureFromImage返回错误6683

我目前正在尝试使用YUV420格式(双平面)在openGL中绘制图像.我收到原始数据,并尝试将其解析为CVPixelBuffer,然后使用CVOpenGLESTextureCacheCreateTextureFromImage传递所述缓冲区.虽然在解析CVPixelBuffer时没有收到任何错误,但在尝试传递给CVOpenGLESTextureCacheCreateTextureFromImage时收到错误(-6683).我正在尽力遵循Apple的GLCameraRipple示例代码 - 除了我再次使用原始图像数据而不是相机中的数据.

希望有人可以解释我在这里失踪的是什么 - 我认为这是一个缺失的属性......

FYI,平面0是Y平面,平面1是UV平面 - 其中UV平面应该是Y平面的宽度和高度的一半.

size_t numPlanes = image->GetNumPlanes();
size_t planeWidth[numPlanes];
size_t planeHeight[numPlanes];
size_t scanWidth[numPlanes];
void *planeIndex[numPlanes];
for(int i = 0; i<numPlanes; i++){
    i<1 ? planeWidth[i] = image->GetWidth() : planeWidth[i] = image->GetWidth()/2;
    i<1 ? planeHeight[i] = image->GetHeight() : planeWidth[i] = image->GetHeight()/2;
    scanWidth[i] = image->GetScanWidth(i);
    planeIndex[i] = image->GetPlanePointer(i);
}

CVPixelBufferRef pixelBuffer;
CFDictionaryRef empty;
CFMutableDictionaryRef attrs;
empty = CFDictionaryCreate(kCFAllocatorDefault,
                           NULL,
                           NULL,
                           0,
                           &kCFTypeDictionaryKeyCallBacks,
                           &kCFTypeDictionaryValueCallBacks);

attrs = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                  1,
                                  &kCFTypeDictionaryKeyCallBacks,
                                  &kCFTypeDictionaryValueCallBacks);

CFDictionarySetValue(attrs, kCVPixelBufferIOSurfacePropertiesKey, empty);



CVReturn cvError = CVPixelBufferCreateWithPlanarBytes(kCFAllocatorDefault,
                                                      image->GetWidth(), …
Run Code Online (Sandbox Code Playgroud)

yuv ios opengl-es-2.0

7
推荐指数
1
解决办法
6374
查看次数