OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 GVRSDK 创建 IOSurface 图像(纹理)失败 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 17:21
标题: ios - 使用 GVRSDK 创建 IOSurface 图像(纹理)失败

我用 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)cardboardViewGVRCardboardView *)cardboardView drawEyeGVREye)eye withHeadTransformGVRHeadTransform *)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 时,一切正常。

有什么帮助吗?谢谢。



Best Answer-推荐答案


更新:这适用于低质量的视频,但高质量的视频在复制这么多字节时表现不佳。我还没有尝试过,但我的下一个方法是使用带有 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()
}

关于ios - 使用 GVRSDK 创建 IOSurface 图像(纹理)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38215970/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4