2

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

    }

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

4

0 回答 0