2014-11-04 3 views
4

동영상 파일을 재생하는 GPUImageMovie를 사용하고 있습니다.이 파일은 iOS 기기에 녹화되었습니다.GPUImageMovie가 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; 
} 

이렇게하면 문제가 해결됩니다.

관련 문제