我正在将带有SKVideoNode的SKScene映射到SCNBox的一侧。我正在努力使视频的长宽比正确。这是代码:
NSURL * url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"preview.mp4"]];
AVAsset * asset = [AVAsset assetWithURL:url];
AVAssetTrack * track = [[asset tracksWithMediaType:AVMediaTypeVideo] firstObject];
CGSize size = track.naturalSize;
NSLog(@"size w is %f Size h is %f", size.width, size.height);
float max = MAX(size.width, size.height);
size = CGSizeMake(max, max);
SKScene * videoScene = [SKScene sceneWithSize:size];
videoScene.scaleMode = SKSceneScaleModeAspectFit;
videoPlayer = [AVPlayer playerWithURL:url];
videoNode = [SKVideoNode videoNodeWithAVPlayer:videoPlayer];
videoNode.position = CGPointMake(size.width/2, size.height/2);
videoNode.size = size;
videoNode.yScale = -1;
[videoNode play];
[videoScene addChild:videoNode];
for (int n = 0; n < 6; n++){
SCNMaterial * material = [SCNMaterial material];
material.diffuse.contents = (n == 4) ? videoScene : bodyImage;
[materials addObject:material];
}
它忽略了任何宽高比设置,例如“适合”和“填充”。它只是将其压扁以适合边界框。将边界框设置得更大似乎没有帮助。即使是相对于视频的固定大小,宽高比也将被忽略。