SKVideoNode not respecting aspect ratio

368 views Asked by At

I'm mapping an SKScene with SKVideoNode onto one of the sides of a SCNBox. I'm struggling to get the aspect ratio of the video correct. Here's the code:

    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];

    }

It's ignoring any aspect ratio settings, like fit and fill. It just squashes it to fit the bounding box. Setting the bounding box bigger doesn't seem to help. Even at a fixed size relative to the video the aspect ratio is ignored.

0

There are 0 answers