Between various things being deprecated, and the new Photos framework (which looks cool but seemed a bit heavyweight for this purpose) finding this took me a while!
// Gets the asset - note ALAsset is deprecated, not AVAsset. AVAsset *asset = [AVAsset assetWithURL:mediaUrl]; // Calculate a time for the snapshot - I'm using the half way mark. CMTime duration = [asset duration]; CMTime snapshot = CMTimeMake(duration.value / 2, duration.timescale); // Create a generator and copy image at the time. // I'm not capturing the actual time or an error. AVAssetImageGenerator *generator = [AVAssetImageGenerator assetImageGeneratorWithAsset:asset]; CGImageRef imageRef = [generator copyCGImageAtTime:snapshot actualTime:nil error:nil]; // Make a UIImage and release the CGImage. UIImage *thumbnail = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef); // TODO: Do something with the image!
Also useful when using the simulator: test videos. Download, open on the simulator, and then save via the share button as for images.
This is something I was working on for Digital Fan Clubs.