Andiih
Andiih

Reputation: 12413

Programmatically access orientation of an iPhone video

I need to access a video returned by the UIImagePickerController and know if it was recorded portrait or landscape. I've seen references to mov_read_tkhd but I'm not sure if that will do the job, or indeed how to include the necessary libraries.

Upvotes: 1

Views: 1696

Answers (1)

Adam
Adam

Reputation: 33126

On iOS 4 and above, with 3GS/3rd gen iTouch or better, you can use the new AVFoundation libraries.

Something like:

NSURL *url = // url to the video returned by the picker
AVAssetTrack *videoTrack = [[url tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0];
videoTrack.preferredTransform; // CGAffineTransform that tells you whether the video is rotated from original orientation
videoTrack.naturalSize; // CGSize that tells you the current dimensions of the video

Upvotes: 1

Related Questions