Question

Why is it that when you load portrait JPGS and try to use AVAssetWriter the resulting mov file is rotated 90?

Ane else seen this?

Was it helpful?

Solution

If the portrait jpgs were made on the iphone, their native pixel format is actually landscape. There is a metadata flag which tells iOS to rotate the view when the jpg is displayed to show it in the correct orientation.

I would guess that when you use AVAssetWriter to create a mov, the mov does not make use of orientation metadata. So it will show the mov in the native pixel orientation, which is landscape. The image will appear to have been rotated 90deg clockwise. There is a possibility (which I haven't tested) that you can carry over the orientation metadata into the mov file, but that's not going to be a very robust solution as it will depend on playback/presentation in metadata-aware environments.

The best way to fix this will be to check the orientation flag, and if it is portrait, physically rotate the jpg to portrait and write it to a new bitmap. Use this new bitmap as input for AVAssetWriter.

Here is some related info:
Captured photo automatically rotated during upload in IOS 6.0 or iPhone
Force UIImagePickerController to take photo in portrait orientation/dimensions iOS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top