First frame of a video using AVFoundation

I solved it. Apparently using [NSURL fileURLWithPath:videoPath] instead of [NSURL URLWithString:videoPath] makes all the difference.


I used null0pointer solution but in some videos I recieved the first frame rotated. To resolve this issue I set to TRUE the appliesPreferredTrackTransform property of AVAssetImageGenerator. And this code looks like this:

AVURLAsset* asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];
AVAssetImageGenerator* imageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset];
[imageGenerator setAppliesPreferredTrackTransform:TRUE];
UIImage* image = [UIImage imageWithCGImage:[imageGenerator copyCGImageAtTime:CMTimeMake(0, 1) actualTime:nil error:nil]];
[self.imageView setImage:image];