【发布时间】:2021-12-23 03:07:12
【问题描述】:
我有一个要渲染到 SCNPlane 上的视频层。它适用于模拟器,但不适用于设备。
这是一个视觉效果:
代码如下:
//DISPLAY PLANE
SCNPlane * displayPlane = [SCNPlane planeWithWidth:displayWidth height:displayHeight];
displayPlane.cornerRadius = cornerRadius;
SCNNode * displayNode = [SCNNode nodeWithGeometry:displayPlane];
[scene.rootNode addChildNode:displayNode];
//apply material
SCNMaterial * displayMaterial = [SCNMaterial material];
displayMaterial.diffuse.contents = [[UIColor greenColor] colorWithAlphaComponent:1.0f];
[displayNode.geometry setMaterials:@[displayMaterial]];
//move to front + position for rim
displayNode.position = SCNVector3Make(0, rimTop - 0.08, /*0.2*/ 1);
//create video item
NSBundle * bundle = [NSBundle mainBundle];
NSString * path = [bundle pathForResource:@"tv_preview" ofType:@"mp4"];
NSURL * url = [NSURL fileURLWithPath:path];
AVAsset * asset = [AVAsset assetWithURL:url];
AVPlayerItem * item = [AVPlayerItem playerItemWithAsset:asset];
queue = [AVQueuePlayer playerWithPlayerItem:item];
looper = [AVPlayerLooper playerLooperWithPlayer:queue templateItem:item];
queue.muted = true;
layer = [AVPlayerLayer playerLayerWithPlayer:queue];
layer.frame = CGRectMake(0, 0, w, h);
layer.videoGravity = AVLayerVideoGravityResizeAspectFill;
displayMaterial.diffuse.contents = layer;
displayMaterial.doubleSided = true;
[queue play];
//[self.view.layer addSublayer:layer];
我可以确认实际飞机存在(如果未应用 avplayerlayer,则在上图中显示为绿色)- 上图第一张。如果视频层直接添加到父视图层(上面的底线),它运行良好 - 上面的最终图像。我认为这可能是文件系统问题,但后来我想(?)视频不会在最终图像中播放。
编辑:设置队列(AVPlayer)直接在模拟器上工作,虽然丑得要命,并且在设备上崩溃,并带有以下错误日志:
Error: Could not get pixel buffer (CVPixelBufferRef)
validateFunctionArguments:3797: failed assertion `Fragment Function(commonprofile_frag): incorrect type of texture (MTLTextureType2D) bound at texture binding at index 4 (expect MTLTextureTypeCube) for u_radianceTexture[0].'
【问题讨论】:
-
日志中有内容吗?它是否适用于其他电影文件?
-
@mnuages 不幸的是,日志文件中没有任何内容。尝试使用另一个 mp4,结果相同。
-
你试过直接设置
AVQueuePlayer作为素材内容吗? (不涉及AVPlayerLayer)。 -
我怀疑这可能与设备上不同的加载特性有关。试试这个答案中的代码:stackoverflow.com/questions/47816292/avasset-tracks-is-empty/…
-
查看日志...不知道是不是应用了材料导致了崩溃。
标签: swift objective-c avfoundation scenekit