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;
}
アプリのこの部分は、(私はすべてのデバイスの向き上で必要として、ビデオを参照してください正常に動作します)。 サムネイル(またはビデオを再生しようとするとき)に問題があります。
私はトラックごとに次の操作を行い、他の質問で読んだとおり:1 - 風景右、2 - 風景左:
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つのサンプルファイルを持っています。上記のコードでは向きが異なることが予想されますが、予期せず同じものがあります(videoAngleInDegreeも同じです)。
回避策はありますか?