gpt4 book ai didi

ios - 拍摄 AVPlayer 的屏幕截图但它适用于某些视频

转载 作者:行者123 更新时间:2023-11-28 12:48:36 26 4
gpt4 key购买 nike

我正在用这个截取 avPlayer 的屏幕截图..

    print(startTime)
print(Float64(startTime))
var time: CMTime = CMTimeMakeWithSeconds(Float64(startTime), 100000000)

do {
print(time)
let imageRef: CGImageRef = try imageGenerator.copyCGImageAtTime(time, actualTime: &time)
let thumbnail: UIImage = UIImage(CGImage: imageRef)



UIImageWriteToSavedPhotosAlbum(thumbnail, nil, nil, nil)

在这里,我正在获取屏幕截图,但当我想要时它并不完美。但对于某些视频,它工作完美。请指导我,谢谢。

最佳答案

得到确切的解决方案...

func screenshotCMTime(cmTime: CMTime)  -> (UIImage)?
{
guard let player = player,let asset = player.currentItem?.asset else
{
return nil
}
let imageGenerator = AVAssetImageGenerator(asset: asset)

var timePicture = kCMTimeZero
imageGenerator.appliesPreferredTrackTransform = true
imageGenerator.requestedTimeToleranceAfter = kCMTimeZero
imageGenerator.requestedTimeToleranceBefore = kCMTimeZero
do {
let ref = try imageGenerator.copyCGImageAtTime(cmTime, actualTime: &timePicture)

image = UIImage(CGImage: ref)
}catch {
error as NSError

}
return image
}

关于ios - 拍摄 AVPlayer 的屏幕截图但它适用于某些视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37225058/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com