IOS Detect video orientation
/* Detect movie orientation */
+ (UIInterfaceOrientation)detectOrientationMovie:(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;
}
return UIInterfaceOrientationPortrait;
}
/* Detect movie orientation */
+ (UIInterfaceOrientation)detectOrientationMovieWithPath:(NSString*) path {
NSURL* video_inputFileUrl = [NSURL fileURLWithPath:path];
AVURLAsset* videoAsset = [[[AVURLAsset alloc]initWithURL:video_inputFileUrl options:nil] autorelease];
AVAssetTrack *videoTrack = [[videoAsset 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;
}
return UIInterfaceOrientationPortrait;
}
+ (UIInterfaceOrientation)detectOrientationMovie:(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;
}
return UIInterfaceOrientationPortrait;
}
/* Detect movie orientation */
+ (UIInterfaceOrientation)detectOrientationMovieWithPath:(NSString*) path {
NSURL* video_inputFileUrl = [NSURL fileURLWithPath:path];
AVURLAsset* videoAsset = [[[AVURLAsset alloc]initWithURL:video_inputFileUrl options:nil] autorelease];
AVAssetTrack *videoTrack = [[videoAsset 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;
}
return UIInterfaceOrientationPortrait;
}
Comments
Post a Comment