我記錄一些視頻與自定義CaptureSessionManager和上午根據裝置方向旋轉所述預覽層(否則,預覽層是在橫長的左/右顛倒要麼)。這工作到目前爲止。但是......IO <S AVAssetTrack視頻取向
當我嘗試播放視頻,我用下面的代碼來確定視頻的方向:
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
爲左,右方向的錄音。
任何想法?
不錯的代碼片斷來確定視頻方向,謝謝! –