In my application, I create a video from separate images. Everything works fine, the videos are assembled correctly with the correct size and orientation. They are displayed correctly both in the Apple photo app and in MPMoviePlayer and in the isolated folder where I save them.
The problem arises when I try to get a thumb from a movie. The orientation is wrong, and I do not know how to fix it, I saw that there is a property - preferredTransform , but the result is the same for landscape and portrait video.
The url I'm using is the sandbox directory path. Here is a snippet:
- (void) setVideoPath:(NSString *)videoPath { if (videoPath ==_videoPath) { return; } _videoPath = videoPath; AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:_videoPath]]; AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset]; CMTime time = CMTimeMake(1, 1); CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL]; UIImage *thumbnail = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); self.videoImageView.image = thumbnail; }
source share