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.
Please let me know how i can fix this issue.