Intercepting first frame pictures with video URL

For convenience, add a category to UIImage directly. When to use it, you can call it directly.

#import < UIKit/UIKit.h> @interface; UIImage (Video) URL / * * access to video by video first frame picture @param videoURL video connection @return first picture * + (UIImage *) interceptFirstTimeVideoPicture: (* NSURL) videoURL; @end
#import "UIImage+Video.h" #import < AVFoundation/AVFoundation.h> @implementation; UIImage (Video) + (UIImage *) interceptFirstTimeVideoPicture: (* NSURL) videoURL{/ URL AVURLAsset AVURLAsset to create a video based on *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil]; / / AVURLAsset = [[AVAssetImageGenerator Gen AVAssetImageGenerator* create AVAssetImageGenerator object alloc] initWithAsset: asset] according to gen.appliesPreferredTrackTransform; = YES; / / define access frame 0 video screenshot CMTime time = CMTimeMake (0, 10); NSError *error = nil; CMTime actualTime; / / get time at the CGImageRef [gen copyCGImageAtTime: video screenshot image = time actualTime: & actualTime error:& error] ; / / convert CGImageRef to UIImage UIImage *thumb [[UIImage alloc] initWithCGImage: = image]; CGImageRelease (image); return thumb @end;}
Note: the class using AVAssetImageGenerator is to remember to import #import < AVFoundation/AVFoundation.h> header files.
Intercepting first frame pictures with video URL
image.png