0

我正在尝试从imagePickerController. 我使用这个功能,但从 0.1s -> 1s 的图像是相同的,从 1.1 到 2s 也是。有什么办法吗?这是我的功能:

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        picker.dismiss(animated: true)
        let videoURL = info[UIImagePickerController.InfoKey.mediaURL] as! URL
        getAllFrames(videoURL)
    }
var frames:[UIImage] = []
private var generator:AVAssetImageGenerator!
func getAllFrames(_ videoUrl: URL) {
        let asset:AVAsset = AVAsset(url: videoUrl)
        let duration:Double = CMTimeGetSeconds(asset.duration)
        self.generator = AVAssetImageGenerator(asset:asset)
        self.generator.appliesPreferredTrackTransform = true
        var i: Double = 0
        repeat {
            self.getFrame(fromTime: i)
            i = i + 0.1
        } while (i < duration)
        self.generator = nil
    } 
private func getFrame(fromTime:Double) {
        let time:CMTime = CMTimeMakeWithSeconds(fromTime, preferredTimescale: 600)
        let image:CGImage
        do {
            try image = self.generator.copyCGImage(at:time, actualTime:nil)
        } catch {
            return
        }
        self.frames.append(UIImage(cgImage:image))
    }

还是我需要提高视频质量?感谢帮助。

4

0 回答 0