iOS portrait videos rotated 90 degrees CCW with MPMoviePlayerController

200 views Asked by At

In my iOS app, I load videos from a URL and play them in my controller:

  self.player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
  [self presentMoviePlayerViewControllerAnimated:self.player];
  [self.player.view setFrame:CGRectMake(0, 0, 320, self.view.frame.size.height - 44)];
  [self.player play];

  [self.view addSubview:self.player.view];

This works fine for video shot in landscape, but videos that were shot in portrait are always rotated 90 degrees counterclockwise.

How do I check the orientation of the video and ensure it's played in the correct orientation?

enter image description here

2

There are 2 answers

0
Jasper On

You could get the width and height of the video itself with this property to know if its landscape or portrait.

0
Alex Spencer On

how about this:

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