6
我有應用程序記錄視頻。AVAssetTrack preferredTransform總是返回風景
要處理手機旋轉,我有以下代碼:
// called on phone rotation
AVCaptureConnection *previewLayerConnection = [[self previewLayer] connection];
if ([previewLayerConnection isVideoOrientationSupported]) {
[previewLayerConnection setVideoOrientation:[self getVideoOrientation]];
}
和getVideoOrientation功能:
- (AVCaptureVideoOrientation) getVideoOrientation {
UIInterfaceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
AVCaptureVideoOrientation newOrientation = AVCaptureVideoOrientationPortrait;
switch (deviceOrientation) {
case UIInterfaceOrientationPortrait:
NSLog(@"UIInterfaceOrientationPortrait");
newOrientation = AVCaptureVideoOrientationPortrait;
break;
case UIInterfaceOrientationLandscapeLeft:
NSLog(@"UIInterfaceOrientationLandscapeRight");
newOrientation = AVCaptureVideoOrientationLandscapeLeft;
break;
case UIInterfaceOrientationLandscapeRight:
NSLog(@"UIInterfaceOrientationLandscapeLeft");
newOrientation = AVCaptureVideoOrientationLandscapeRight;
break;
default:
NSLog(@"default");
newOrientation = AVCaptureVideoOrientationPortrait;
break;
}
return newOrientation;
}
應用的這部分工作正常(我看到視頻,我應該在任何設備方向)。 但是,當我嘗試製作縮略圖(或播放視頻)時,我遇到了問題。
正如我在我做的每一曲目以下的其他問題已經閱讀:
AVAssetTrack* videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGAffineTransform txf = [videoTrack preferredTransform];
CGFloat videoAngleInDegree = RadiansToDegrees(atan2(txf.b, txf.a));
if (txf.a == 0 && txf.b == 1.0 && txf.c == -1.0 && txf.d == 0) {
thumbOrientation = UIImageOrientationLeft;
}
if (txf.a == 0 && txf.b == -1.0 && txf.c == 1.0 && txf.d == 0) {
thumbOrientation = UIImageOrientationRight;
}
if (txf.a == 1.0 && txf.b == 0 && txf.c == 0 && txf.d == 1.0) {
thumbOrientation = UIImageOrientationUp;
}
if (txf.a == -1.0 && txf.b == 0 && txf.c == 0 && txf.d == -1.0) {
thumbOrientation = UIImageOrientationDown;
}
UIImage *image = [UIImage imageWithCGImage:im scale:1.0 orientation:thumbOrientation];
我有2個樣本文件:1 - 景觀權,2 - 景觀左側。我期望他們在上面的代碼中有不同的方向,但意外的是他們有相同的(而videoAngleInDegree對於他們來說都是一樣的)。
是否有任何解決方法?