Objective c SKVideoNode不考虑纵横比

Objective c SKVideoNode不考虑纵横比,objective-c,skscene,skvideonode,scnmaterial,Objective C,Skscene,Skvideonode,Scnmaterial,我正在将带有SKVideoNode的SKScene映射到SCNBox的一侧。我正在努力使视频的纵横比正确。代码如下: NSURL * url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"preview.mp4"]]; AVAsset * asset = [AVAsset assetWithURL:url]; AVA

我正在将带有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];

    }
NSURL*url=[NSURL fileURLWithPath:[NSString stringWithFormat:@“%@/%@”,[[NSBundle mainBundle]resourcePath],@“preview.mp4”];
AVAsset*asset=[AVAsset AssetTwithUrl:url];
AVAssetTrack*track=[[asset Tracks SwithMediaType:AVMediaTypeVideo]第一个对象];
CGSize size=track.naturalSize;
NSLog(@“尺寸w为%f,尺寸h为%f”,尺寸.宽度,尺寸.高度);
浮动最大值=最大值(尺寸.宽度,尺寸.高度);
尺寸=CGSizeMake(最大值,最大值);
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=大小;
videoNode.yScale=-1;
[视频节点播放];
[视频场景添加子节点:视频节点];
对于(int n=0;n<6;n++){
SCN物料*物料=[SCN物料];
material.diffuse.contents=(n==4)?视频场景:bodyImage;
[物料添加对象:物料];
}

它会忽略任何纵横比设置,如“拟合”和“填充”。它只是挤压它以适应边界框。将边界框设置得更大似乎没有帮助。即使在相对于视频的固定大小下,纵横比也会被忽略。

请注意,如果您只支持iOS 11及以上版本,则不需要AVPlayer>SKVideoNode>SKScene>SCNMaterialProperty-您可以直接将
diffuse.contents
设置为AVPlayer。我尝试直接设置播放器层,但不需要花费时间。你知道这方面的代码吗?不是播放器层,只是播放器-per,
SCNMaterialProperty。内容可以在iOS 11及更高版本中获取
AVPlayer
对象。如果该播放器也连接到播放器层,您可能会有问题,也可能不会有问题。我也遇到了这个问题。将AVPlayer直接设置为diffuse.contents有效-谢谢。但是没有解决纵横比问题。顺便说一句,这看起来很相关:稍后再看。