Friday, February 5, 2010

iPhone Video Orientation (Tallscreen/Vertical Video)

We have been working with Encoding.com recently to get "tallscreen" (vertically-oriented viewing mode) support working on incoming iPhone videos. Encoding.com now finally supports these videos, but you will need to recognize things correctly on your end, or you won't like the results.

In short, you need to recognize that the video is vertically oriented, and if it is, you want to swap your output WIDTH and HEIGHT numbers in your encoding.com request. If you do that, encoding.com will do the rest.

To understand why, here is what I've learned about how iPhone video works...

The iPhone records video to disk the same way each time: as if you've turned the phone 90 degrees to the left, and put it in landscape mode. This is considered "0 degrees," and the video is recorded in this landscape mode, at 640 x 480 (4:3), no matter which way you have the phone oriented.

If you turn the phone to any of the other positions, it doesn't change the way it writes the bits on disk, it just records the "Rotation" flag according to the orientation the phone was in when the recording process started.

  • 0 degrees: landscape, turned on the phone's left side
  • 90 degrees: vertical/normal, with home button on bottom
  • 180 degrees: landscape, but turned on the phone's right side instead of left
  • 270 degrees: vertical/upside-down, with home button on top
All of Apple's recent video players (i.e. Quicktime) are aware of this rotation flag, and so you might never realize your video is being recorded the way it is until you try to view it on a player that doesn't support it, or encode the video with an encoder that doesn't recognize it. In one of these players or encoders, the video would look to be turned on it's side or upside down.

Encoding.com now supports this flag, and I have confirmed it recognizes it correctly in all 4 positions.

So the only thing you need to do is to recognize that if the rotation is 90 or 270, you need to flip the Width and Height numbers, that's it. Encoding.com does the rest.

So, for example, a user uploads a vertically-oriented video to you (either 90 or 270 degree rotation), recorded at the usual iPhone 640 x 480. You see that it's rotated, and your encoding.com request specifies that the output you want is now flipped, 480 x 640 (W x H). Encoding.com gets your source video, sees the rotation flag, and flips it properly while encoding -- and since you specified the proper output size, the video comes out as expected!

(If the video rotation is 180 degrees, you don't need to do anything. The W x H does not change, since it's still in landscape, and encoding.com will correctly flip the video 180 degrees when encoding it.)

Currently we are using the open source "MediaInfo" program to easily obtain information about an incoming video, and to find whether or not the "Rotation" flag has been set, and to what.

1 comment:

Sweet Fairy said...

Çok detaylı ile yazılan güzel. Ben sizin bilgi gerçekten takdir. Bunu daha önce hiç duymadım. Paylaşım için teşekkürler. ucuz iphone 4