从UIImagePickerController中挑选后旋转视频以上传到服务器

时间:2013-01-05 19:22:28

标签: iphone xcode uiimagepickercontroller

所以我看到了这些答案以及其他许多答案:

How to detect (iPhone SDK) if a video file was recorded in portrait orientation, or landscape.

How do I rotate a video from UIImagePickerController before uploading to a webserver

我理解如何从UIImagePickerController获取视频的方向但是如何实际旋转Image Picker返回的视频网址,以便在我上传时不旋转90度?

编辑:

我正在使用此方法来获取视频的方向。在我获得视频方向后,如何将其实际旋转到返回的方向?

- (UIInterfaceOrientation)orientationForTrack:(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;
}

1 个答案:

答案 0 :(得分:0)

- (UIImageOrientation)getImageOrientationWithVideoOrientation:(UIInterfaceOrientation)videoOrientation {
UIImageOrientation imageOrientation;
switch (videoOrientation) {
    case UIInterfaceOrientationLandscapeLeft:
        imageOrientation = UIImageOrientationUp;
        break;
    case UIInterfaceOrientationLandscapeRight:
        imageOrientation = UIImageOrientationDown;
        break;
    case UIInterfaceOrientationPortrait:
        imageOrientation = UIImageOrientationRight;
        break;
    case UIInterfaceOrientationPortraitUpsideDown:
        imageOrientation = UIImageOrientationLeft;
        break;
}
return imageOrientation;
}