我正在使用自定义 CaptureSessionManager 录制一些视频,并根据设备方向旋转预览层(否则,预览层在横向左/右上是颠倒的)。到目前为止,这有效。但...
当我尝试播放视频时,我使用以下代码来确定视频的方向:
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;
但结果总是一样的,不管是左还是右。
我使用此代码来获取输出:
AVAssetTrack *videoTrack = [[asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
CGSize size = [videoTrack naturalSize];
CGAffineTransform txf = [videoTrack preferredTransform];
NSLog(@"Transformation a %f - b %f - c %f - d %f", txf.a, txf.b, txf.c, txf.d);
NSLog(@"Transformation tx %f - ty %f", txf.tx, txf.ty);
NSLog(@"Size width: %f - height: %f", size.width, size.height);
这导致:
Transformation a -1.000000 - b 0.000000 - c 0.000000 - d -1.000000
Transformation tx 1920.000000 - ty 1080.000000
Size width: 1920.000000 - height: 1080.000000
左右方向记录。
有任何想法吗?