我使用AVCaptureSession
会话预设
session!.sessionPreset = AVCaptureSessionPreset1280x720
使用此代码从视频中提取图像
func videoThumbnails(url: NSURL ){
let asset = AVAsset(URL: url)
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true
imageGenerator.maximumSize = CGSizeMake(720, 1280)
imageGenerator.requestedTimeToleranceAfter = kCMTimeZero
var time = asset.duration
let totalTime = time
var frames = 0.0
let singleFrame = Double(time.seconds) / 4
while (frames < totalTime.seconds) {
frames += singleFrame
time.value = (Int64(frames)) * Int64(totalTime.timescale)
do {
let imageRef = try imageGenerator.copyCGImageAtTime(time, actualTime: nil)
self.sendImage.append(UIImage(CGImage: imageRef))
}
catch let error as NSError
{
print("Image generation failed with error \(error)")
}
}
self.performSegueWithIdentifier("showCapturedImages", sender: nil)
}
现在您可以检查视频上方的图像,以便检查色差。
现在我想要的是从视频中提取精确的图像。怎么办?