Extract image from video, image color is fast

I am shooting a video using a AVCaptureSessionsession preset

session!.sessionPreset = AVCaptureSessionPreset1280x720

and extract the image from the video using this code

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)

}

Now you can check the image above the video so that you can check the color difference.

enter image description here

Now I want to extract the exact image from the video. how to do it?

+4
source share

Source: https://habr.com/ru/post/1671259/


All Articles