【问题标题】:Failed to create IOSurface image (texture) with GVRSDK使用 GVRSDK 创建 IOSurface 图像(纹理)失败
【发布时间】:2016-11-08 00:44:15
【问题描述】:

我用 SKVideoNode 创建了一个 SKScene,然后应用到一个球体几何体。

这里是关键代码:

// Create a SKScene to play video
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"2222" ofType:@"mp4"];
NSURL* sourceMovieURL = [NSURL fileURLWithPath:filePath];
AVPlayer* player = [AVPlayer playerWithURL:sourceMovieURL];
SKVideoNode* videoNode = [SKVideoNode videoNodeWithAVPlayer:player];

//CGSize size = CGSizeMake(512, 512);
CGSize size = [UIScreen mainScreen].bounds.size;
videoNode.size = size;
videoNode.position = CGPointMake(size.width/2.0, size.height/2.0);
SKScene* spriteScene = [SKScene sceneWithSize:size];
[spriteScene addChild:videoNode];


// create a material with SKScene
SCNMaterial* material = [SCNMaterial material];
material.doubleSided = true;
material.diffuse.contents = spriteScene;


[sphereNode.geometry replaceMaterialAtIndex:0 withMaterial:material];

[videoNode play];

[_scnScene.rootNode addChildNode:sphereNode];

// create SCNRenderer to render the scene
_renderer = [SCNRenderer rendererWithContext:cardboardView.context options:nil];
_renderer.scene = _scnScene;
_renderer.pointOfView = _scnCameraNode;

在drawEye函数中:

- (void)cardboardView:(GVRCardboardView *)cardboardView drawEye:(GVREye)eye withHeadTransform:(GVRHeadTransform *)headTransform
{
//CGRect viewport = [headTransform viewportForEye:eye];

// Get the head matrix.
const GLKMatrix4 head_from_start_matrix = [headTransform headPoseInStartSpace];

// Get this eye's matrices.
GLKMatrix4 projection_matrix = [headTransform projectionMatrixForEye:eye near:_scnCamera.zNear far:_scnCamera.zFar];


GLKMatrix4 eye_from_head_matrix = [headTransform eyeFromHeadMatrix:eye];

// Compute the model view projection matrix.
GLKMatrix4 view_projection_matrix = GLKMatrix4Multiply(
                                                       projection_matrix, GLKMatrix4Multiply(eye_from_head_matrix, head_from_start_matrix));
// Set the projection matrix to camera
[_scnCamera setProjectionTransform:SCNMatrix4FromGLKMatrix4(view_projection_matrix)];


// Render the scene
[_renderer renderAtTime:0];

}

运行代码时会中断

[_renderer renderAtTime:0]

输出是:

Failed to create IOSurface image (texture)
Assertion failed: (result), function create_texture_from_IOSurface, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Jet/Jet-2.6.1/Jet/jet_context_OpenGL.mm, line 570.

当我从 SKScene 中删除 SKVideoNode 时,一切正常。

有什么帮助吗?谢谢。

【问题讨论】:

  • 我们有同样的问题,除了它不会出现在我们所有的设备上......或者可能的 iOS 版本上。您正在运行哪些设备和版本的 iOS、xcode 和 mac?
  • 设备是 iphone 6s, ios9.3.2, Mac mini(Late 2014) OS X EI Caption version 10.11.5 with xcode 7.3.1
  • 因此,我们的工作假设是,在 5s 及更高版本的 ios 9+ 上,操作系统引入了更改或错误。我们认为这可能与 iOS 在这些设备上使用金属而不是 OpenGL 的偏好有关,但现在更多的是猜测。如果我们发现更多,我们会发布更多。
  • 好的,谢谢!但是 GVRSDK 使用 OpenGL 而不是金属,我希望 Google 有一天能解决这个问题!如果您找到任何解决方案,请告诉我。我会很感激的。
  • 我们在带有 SPHERE 和 SKVIDEONODE 的 iOS 10 Beta 中看到了这一点。这在 iOS 9 上运行良好。我们有一个示例应用程序,将 PrefersOpenGL 设置为 NO 并且它可以工作,但是 YES 不起作用并给出同样的问题,但在 iOS 10 Beta 上,并且在 iOS 9 上工作

标签: ios video google-cardboard google-vr skvideonode


【解决方案1】:

更新:这适用于低质量的视频,但高质量的视频在复制这么多字节时表现不佳。我还没有尝试过,但我的下一个方法是使用带有 CVPixelBuffer 的 OpenGL 纹理以获得更好的性能。

-

我不知道您是否仍在寻找解决方案,但我很幸运能够在 iOS 9.3 上的 6s 和 iOS 8 sim 上使用 SceneKit / GVR 的视频球体。但我不能保证所有平台!

我完全放弃了 SpriteKit,转而使用 CALayer,我将其内容设置为 CVPixelBuffer 中的 CGImage。

视频代码:(最初基于this OpenGL 360 video tutorial

init(url: NSURL)
{
    self.videoURL = url
    super.init()
    self.configureVideoPlayback()
}

private override init()
{
    self.videoURL = nil
    super.init()
}

deinit
{
    self.playerItem.removeOutput(self.videoOutput)
}

private func configureVideoPlayback()
{
    let pixelBufferAttributes = [
        kCVPixelBufferPixelFormatTypeKey as String : NSNumber(unsignedInt: kCVPixelFormatType_32ARGB),
        kCVPixelBufferCGImageCompatibilityKey as String: true,
        kCVPixelBufferOpenGLESCompatibilityKey as String: true
    ]
    self.videoOutput = AVPlayerItemVideoOutput(pixelBufferAttributes: pixelBufferAttributes)
    
    self.playerItem = AVPlayerItem(URL: self.videoURL)
    self.playerItem.addOutput(self.videoOutput)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(VideoReader.playerItemDidPlayToEndTime(_:)), name: AVPlayerItemDidPlayToEndTimeNotification, object: self.playerItem)

    self.player = AVPlayer(playerItem: self.playerItem)
    self.player.play()
}   

func currentPixelBuffer() - > CVPixelBuffer ? {
    guard self.playerItem ? .status == .ReadyToPlay
    else {
        return nil
    }
    
    let currentTime = self.playerItem.currentTime()
    return self.videoOutput.copyPixelBufferForItemTime(currentTime, itemTimeForDisplay: nil)
}

func playerItemDidPlayToEndTime(notification: NSNotification)
{
    self.player.seekToTime(kCMTimeZero)
    self.player.play()
}

场景:

func setupScene() {
  self.scene = SCNScene()

  self.imageLayer = CALayer()
  self.imageLayer.frame = CGRectMake(0, 0, 2048, 2048) //Doesn't work if not power of 2 or incremenets inbetween - need to investigate

  let material = SCNMaterial()
  material.doubleSided = true
  material.diffuse.contents = self.imageLayer

  let geometry = SCNSphere(radius: 10)

  let sphere = SCNNode(geometry: geometry)
  sphere.geometry ? .replaceMaterialAtIndex(0, withMaterial: material)
  sphere.position = SCNVector3(0, 0, 0)
  sphere.scale.y = 1
  sphere.scale.z = -1

  self.scene!.rootNode.addChildNode(sphere)
}

纸板并条机准备:

func cardboardView(cardboardView: GVRCardboardView!, prepareDrawFrame headTransform: GVRHeadTransform!) {
  
  // .. boilerplate code

  if let pixelBuffer = self.videoReader.currentPixelBuffer() {
    CVPixelBufferLockBaseAddress(pixelBuffer, 0);

    let width = CVPixelBufferGetWidth(pixelBuffer)
    let height = CVPixelBufferGetHeight(pixelBuffer)
    let pixels = CVPixelBufferGetBaseAddress(pixelBuffer);

    let pixelWrapper = CGDataProviderCreateWithData(nil, pixels, CVPixelBufferGetDataSize(pixelBuffer), nil);

    // Get a color-space ref... can't this be done only once?
    let colorSpaceRef = CGColorSpaceCreateDeviceRGB();

    // Get a CGImage from the data (the CGImage is used in the drawLayer: delegate method above)

    let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.NoneSkipFirst.rawValue)
    if let currentCGImage = CGImageCreate(width,
      height,
      8,
      32,
      4 * width,
      colorSpaceRef, [.ByteOrder32Big, bitmapInfo],
      pixelWrapper,
      nil,
      false,
      .RenderingIntentDefault) {
      self.imageLayer.contents = currentCGImage
    }

    // Clean up
    CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);

  }
}

我最初的 GVR 和 SceneKit 实现是基于这个boilerplate

帧速率对我来说似乎仍然足够高 - 它尚未优化,但我会在优化时更新此答案。

注意:

  • CALayer 边界似乎需要是 2 的幂 - 或增量 在两者之间,当我选择介于之间的值时,它不会显示任何视频 就像 1960 年一样。
  • 它在模拟器中运行非常慢,但在我的设备上运行速度为 60fps

【讨论】:

  • 感谢您的回答!成功了!但是有一个新问题,它会在几秒钟后中断 // 渲染场景 [_renderer renderAtTime:0];然后我使用上面提到的 VRBoilerplate,它也在同一点中断。如果 glGetError() == GLenum(GL_NO_ERROR) { eyeRenderer.renderAtTime(0); }
  • 那不好。您是否尝试过使用其他视频?你用的是哪款手机?我没有放完整的视频代码,因为我认为它不相关,但我现在会更新它,所以它在 AVURLAsset 上使用'loadValuesAsynchronouslyForKeys' - 视频阅读器部分基于本教程nomtek.com/video-360-in-opengl-ios-part-4-video-reader跨度>
  • 实际上使用 AVPlayer 而不是 AVURLAsset 可能更容易。如果 GL 代码一开始运行平稳,则假设问题出在视频播放上。我已经简化了答案中的代码,希望对您有所帮助。如果没有尝试将错误通知侦听器添加到 AVPlayerItem
  • 好的,谢谢!我试试看。
  • 这似乎工作正常。你对它给 CPU/GPU 带来的额外压力有感觉吗?另外,我的印象是,cardboardView 在每次渲染过程中都会被调用,而如果视频尚未移动到新帧,则不调用它就足够了。您是否尝试过大型视频,例如 4k 等?
【解决方案2】:

我认为原因是 SDK 将 SCNView 的渲染 API 设置为 OpenGLES。只需将 API 设置为默认(金属)即可解决此问题。

检查是否有类似的代码:

[[SVNView alloc] initWithFrame:CGRect() options:@{SCNPreferredRenderingAPIKey: [NSNumber numberWithInt:SCNRenderingAPIOpenGLES2]}]

把这个改成:

[[SVNView alloc] initWithFrame:CGRect() options:nil] or [[SVNView alloc] initWithFrame:CGRect()]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-31
    • 2014-09-23
    相关资源
    最近更新 更多