James Campbell
James Campbell

Reputation: 3591

GPUImageMovie not respecting imageOrientation

I am using GPUImageMovie which is playing a movie file, this file was recorded on a iOS device.

However when GPUImageMovie plays it it is in the wrong orientation so the video isn't rotated to be shown correctly.

How do I get it to respect it's orientation ? I've tried modifying the OpenGL code with no luck.

Upvotes: 4

Views: 728

Answers (2)

andrewchan2022
andrewchan2022

Reputation: 5290

add to @Ameet Dhas: one place to set rotation is where before call next filter.

[currentTarget setInputRotation:outPutRotation atIndex:targetTextureIndex];
[currentTarget newFrameReadyAtTime:currentSampleTime atIndex:targetTextureIndex];

Upvotes: 0

Bhushan B
Bhushan B

Reputation: 2510

I had same problem when playing a video recorded in iOS device using GPUImageMovie. I solved it using following functions :

Call this setRotationForFilter: method by passing you filter. The orientationForTrack: will return your current video orientation.

- (void)setRotationForFilter:(GPUImageOutput<GPUImageInput> *)filterRef {
    UIInterfaceOrientation orientation = [self orientationForTrack:self.playerItem.asset];
    if (orientation == UIInterfaceOrientationPortrait) {
        [filterRef setInputRotation:kGPUImageRotateRight atIndex:0];
    } else if (orientation == UIInterfaceOrientationLandscapeRight) {
        [filterRef setInputRotation:kGPUImageRotate180 atIndex:0];
    } else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
        [filterRef setInputRotation:kGPUImageRotateLeft atIndex:0];
    }
}

- (UIInterfaceOrientation)orientationForTrack:(AVAsset *)asset
{
    AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
    CGSize size = [videoTrack naturalSize];
    CGAffineTransform txf = [videoTrack preferredTransform];

    if (size.width == txf.tx && size.height == txf.ty)
        return UIInterfaceOrientationLandscapeRight;
    else if (txf.tx == 0 && txf.ty == 0)
        return UIInterfaceOrientationLandscapeLeft;
    else if (txf.tx == 0 && txf.ty == size.width)
        return UIInterfaceOrientationPortraitUpsideDown;
    else
        return UIInterfaceOrientationPortrait;
}

Hope this solves your issue.

Upvotes: 9

Related Questions