从视频中提取图像,图像颜色不同迅速

时间:2017-03-02 14:35:30

标签: ios swift avfoundation avcapturesession avassetimagegenerator

我使用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)

}

现在您可以检查视频上方的图像,以便检查色差。

enter image description here

现在我想要的是从视频中提取精确的图像。怎么办?

0 个答案:

没有答案