看起来很简单。我只想要视频 5 秒内的缩略图:
AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:[NSURL URLWithString:url] options:nil];
AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];
generate1.appliesPreferredTrackTransform = YES;
NSError *err = NULL;
Float64 seconds = 5;
int32_t preferredTimeScale = 30;
CMTime actualTime;
CMTime inTime = CMTimeMakeWithSeconds(seconds, preferredTimeScale);
CMTimeShow(inTime);
CGImageRef oneRef = [generate1 copyCGImageAtTime:inTime actualTime:&actualTime error:&err];
输出是这样的:
Printing description of actualTime:
(CMTime) actualTime = 83 1000ths of a second {
value = 83
timescale = 1000
flags = kCMTimeFlags_Valid
epoch = 0
}
Printing description of inTime:
(CMTime) inTime = 150 30ths of a second {
value = 150
timescale = 30
flags = kCMTimeFlags_Valid
epoch = 0
}
为什么不actualTime
一样inTime
???如何在视频中获得 5 秒的图像?