GPUImageMovie不尊重imageOrientation

Jam*_*ell 4 ios gpuimage

我正在使用正在播放电影文件的GPUImageMovie,这个文件是在iOS设备上录制的.

但是,当GPUImageMovie播放时,它的方向错误,因此视频不会旋转以便正确显示.

我如何让它尊重它的方向?我试过没有运气修改OpenGL代码.

Ame*_*has 8

使用GPUImageMovie播放在iOS设备中录制的视频时遇到同样的问题.我用以下函数解决了它:

setRotationForFilter:通过传递过滤器来调用此方法.这orientationForTrack:将返回您当前的视频方向.

- (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;
}
Run Code Online (Sandbox Code Playgroud)

希望这能解决您的问题.