0

I have been trying to generate thumbnails from video and same them to my server. I am using Swift language and using AVFoundation to generate the thumbnail of the video that is picked from the phone or recorded from the camera. The thumbnail is successfully generated but for some videos it gets rotated upside down. This is the code i have written.

func getThumbnailImage(forUrl url: URL) -> UIImage? {
       let asset: AVAsset = AVAsset(url: url)
       let imageGenerator = AVAssetImageGenerator(asset: asset)

       do {
           let thumbnailImage = try imageGenerator.copyCGImage(at: CMTimeMake(value: 1, timescale: 60) , actualTime: nil)
           return UIImage(cgImage: thumbnailImage)
       } catch let error {
           print(error)
       }

       return nil
   }

This is how i get the video url.

var u = info[UIImagePickerController.InfoKey.mediaURL] as? URL

Here is the image of thumbnail getting rotated. The video is upside but the thumbnail is upside down. Thumnail Rotated

Please let me know how i can fix this issue.

1 Answers1

0

Your question already has an answer here .

More generally conventional photo formats has a metadata field that corresponds to the orientation of the media, transcoding the media can result to erasing this metadata (according to the library/procedure you're using), if you want to know more you should take a look to the exif format.

Asya Corbeau
  • 209
  • 1
  • 4