0

我正在尝试捕获相机输出帧并在 GPU 管道中进一步处理它。出于这个原因,将帧重新作为 GPU 纹理是最好的选择。从run方法接收的QVideoFilterRunnable类继承后,QVideoFrame对象的类型不等于QAbstractVideoBuffer::GLTextureHandle。它等于,我需要手动执行映射/取消映射和加载纹理,这对性能不利。是否有任何控制选项可用于返回纹理名称?NoHandleglTexImage

一些注意事项:

  • 在安卓上看起来不错。返回的帧是纹理,所以这就像一个魅力:

    QVideoFrame* input = ...;
    GLuint texture = input->handle().toUInt(); 
    f->glBindTexture(GL_TEXTURE_2D, texture);
    
  • 一般来说,有可能,有 iOS 纹理缓存功能:

    CVPixelBufferRef pixelBuffer = ...;
    CVOpenGLESTextureCacheCreateTextureFromImage(..., pixelBuffer, ..., &textureRef);
    texture = CVOpenGLESTextureGetName(textureRef);
    
4

1 回答 1

0

CVPixelBufferRef可以手动创建(我map仍然需要使用):

frame.map(QAbstractVideoBuffer::ReadOnly);

CVPixelBufferRef x;
CVPixelBufferCreateWithBytes(
    kCFAllocatorDefault,
    frame.size().width(),
    frame.size().height(),
    kCVPixelFormatType_32BGRA,
    frame.bits(),
    frame.bytesPerLine(),
    nullptr, // releaseCallback
    nullptr, // releaseRefCon
    nullptr, // pixelBufferAttributes
    &x
);

使用CVPixelBufferRef指针的值创建缓存纹理:

CVOpenGLESTextureRef texRef;
CVOpenGLESTextureCacheCreateTextureFromImage(
    kCFAllocatorDefault,
    textureCache,
    x,
    NULL, // texture attributes
    GL_TEXTURE_2D,
    GL_RGBA, // opengl format
    inputW,
    inputH,
    inputPixelFormat,
    GL_UNSIGNED_BYTE,
    0,
    &texRef
);

获取纹理名称:

inputTexId = CVOpenGLESTextureGetName(texRef);
于 2015-12-21T17:03:41.633 回答