ios - 使用 GVRSDK 创建 IOSurface 图像(纹理)失败
<p><p>我用 SKVideoNode 创建了一个 SKScene,然后应用到一个球体几何体。</p>
<p>这里是关键代码:</p>
<pre><code>// Create a SKScene to play video
NSString* filePath = [ pathForResource:@"2222" ofType:@"mp4"];
NSURL* sourceMovieURL = ;
AVPlayer* player = ;
SKVideoNode* videoNode = ;
//CGSize size = CGSizeMake(512, 512);
CGSize size = .bounds.size;
videoNode.size = size;
videoNode.position = CGPointMake(size.width/2.0, size.height/2.0);
SKScene* spriteScene = ;
;
// create a material with SKScene
SCNMaterial* material = ;
material.doubleSided = true;
material.diffuse.contents = spriteScene;
;
;
;
// create SCNRenderer to render the scene
_renderer = ;
_renderer.scene = _scnScene;
_renderer.pointOfView = _scnCameraNode;
</code></pre>
<p>在drawEye函数中:</p>
<pre><code>- (void)cardboardView:(GVRCardboardView *)cardboardView drawEye:(GVREye)eye withHeadTransform:(GVRHeadTransform *)headTransform
{
//CGRect viewport = ;
// Get the head matrix.
const GLKMatrix4 head_from_start_matrix = ;
// Get this eye's matrices.
GLKMatrix4 projection_matrix = ;
GLKMatrix4 eye_from_head_matrix = ;
// 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
;
// Render the scene
;
}
</code></pre>
<p>运行代码时会中断</p>
<pre><code>
</code></pre>
<p>输出是:</p>
<pre><code>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.
</code></pre>
<p>当我从 SKScene 中删除 SKVideoNode 时,一切正常。 </p>
<p>有什么帮助吗?谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>更新:</strong>这适用于低质量的视频,但高质量的视频在复制这么多字节时表现不佳。我还没有尝试过,但我的下一个方法是使用带有 CVPixelBuffer 的 OpenGL 纹理以获得更好的性能。</p>
<p>-</p>
<p>我不知道您是否仍在寻找解决方案,但我很幸运能够在 iOS 9.3 上的 6s 和 iOS 8 sim 上使用 SceneKit/GVR 的视频球体。但我不能保证所有平台!</p>
<p>我完全放弃了 SpriteKit,转而使用 CALayer,我将其内容设置为 CVPixelBuffer 中的 CGImage。</p>
<p><strong>视频代码:</strong>(最初基于<a href="https://www.nomtek.com/video-360-in-opengl-ios-part-4-video-reader/" rel="noreferrer noopener nofollow">this OpenGL 360 video tutorial</a>)</p>
<p></p><div class="snippet"data-lang="js"data-hide="false"data-console="true"data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>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()
}</code></pre>
<p style="font-size: 20px;">关于ios - 使用 GVRSDK 创建 IOSurface 图像(纹理)失败,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/38215970/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/38215970/
</a>
</p>
页:
[1]