2014-11-04 47 views
4

我正在使用正在播放電影文件的GPUImageMovie,此文件已記錄在iOS設備上。GPUImageMovie not respect the imageOrientation

但是,當GPUImageMovie播放它時,它的方向錯誤,因此視頻不能正確顯示。

我該如何去尊重它的方向?我已經嘗試修改OpenGL代碼而沒有運氣。

回答

6

我在使用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; 
} 

希望這可以解決您的問題。

相關問題