If you use MPMoviePlayerController , you can use this code to generate thumbnails from the video URL.
NSString *stringUrl = video.stringurl; NSURL *url = [NSURL URLWithString:stringUrl]; MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url]; UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
But, using this code, the player will start auto-playing sound. So you must stop the player with this code:
//Player autoplays audio on init [player stop];
Update:
Image save error Domain error = AVFoundationErrorDomain Code = -11800 "operation could not be completed" (OSStatus error -12792.) ", NSLocalizedFailureReason = An unknown error occurred (-12792)}
The error is probably related to using URLWithString . I think you should use -fileURLWithPath instead of URLWithString .
Code example:
NSString *stringUrl = video.stringurl; NSURL *vidURL = [NSURL fileURLWithPath:stringUrl]; AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:vidURL options:nil]; AVAssetImageGenerator *generate = [[AVAssetImageGenerator alloc] initWithAsset:asset]; NSError *err = NULL; CMTime time = CMTimeMake(1, 60); CGImageRef imgRef = [generate copyCGImageAtTime:time actualTime:NULL error:&err]; UIImage *thumbnail = [UIImage imageWithCGImage:imgRef];
source share