How can I set the UIImagePickerController orientat

2020-03-08 07:49发布

My app uses the UIImagePickerController to record a video, and I'm then uploading it to our Amazon server using ASIS3Request.

Whilst the video always plays in the correct orientation on the device, the orientation is wrong when viewed in some browsers.

Is there a way for me to manually set the orientation of the phone onto the image file when it's being taken? Or is the problem exclusively with the browsers (and if so, how can I fix that)?

Thank you. S.O. for president!

Duncan

1条回答
孤傲高冷的网名
2楼-- · 2020-03-08 08:05

the iPhone sets the orientation in the exif data of the video. It will play back just fine in quicktime, but everywhere else has it rotated wrong.

There are two ways to solve it, rotate it on device, or up in the cloud. You can ask the video for it's preferred transform on the device and that will let you know what you need to rotate it.

   AVURLAsset * footageVideo = [AVURLAsset URLAssetWithURL:assetURL options:nil];
   AVAssetTrack * footageVideoTrack = [footageVideo compatibleTrackForCompositionTrack:videoTrack];

   CGAffineTransform t = footageVideoTrack.preferredTransform;

Once you have the transform you can use an AVExportSession to rotate the video, although this can take quite some time on device.

查看更多
登录 后发表回答