Create a video resource object
Avasset *asset = [Avasset AssetWithURL:self.mpc.contentURL];
Video Picture Builder Object
Avassetimagegenerator *generator = [Avassetimagegenerator assetimagegeneratorwithasset:asset];
//
Value the first few frames
Timescale How many frames are played per second
Cmtime time = Cmtimemake (< #int64_t value#>, int32_t timescale)
Currentplaybacktime Current video playback time, Unit is s
Asset.duration duration of video
Cmtime time = Cmtimemakewithseconds (Self.mpc.currentplaybacktime,asset.duration.timescale);
Nsvalue *timevalue = [Nsvalue valuewithcmtime:time];
[Generator Generatecgimagesasynchronouslyfortimes:@[timevalue] completionhandler:^ (Cmtime requestedTime, Cgimageref image, Cmtime actualtime, avassetimagegeneratorresult result, Nserror *error) {
There is a time delay when the Uiimageview picture is not updated in the main thread
NSLog (@ "%@", [Nsthread CurrentThread]);
NSLog (@ "capture picture succeeded");
Asynchronous task: does not block the task of the current thread
Dispatch_sync (Dispatch_get_main_queue (), ^{
//
Self.imageView.image = [UIImage imagewithcgimage:image];
// });
Dispatch_async (Dispatch_get_main_queue (), ^{
Self.imageView.image = [UIImage imagewithcgimage:image];
});
//
}];
Video code