gpt4 book ai didi

objective-c - 在当前时间创建 AVPlayer 的缩略图或图像

转载 作者:太空狗 更新时间:2023-10-30 03:15:20 30 4
gpt4 key购买 nike

我已经实现了一个 AVPlayer,我想在单击工具栏按钮时拍摄图像或缩略图,并在新的 UIViewController 中打开 UIImageView。图像应该像 AVPlayer 一样缩放。segue 已经开始工作,我只需要实现在当前播放时间获取图像即可。

谢谢!

最佳答案

Objective-C

AVAsset *asset = [AVAsset assetWithURL:sourceURL];
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc]initWithAsset:asset];
CMTime time = CMTimeMake(1, 1);
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:time actualTime:NULL error:NULL];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef); // CGImageRef won't be released by ARC

swift

var asset = AVAsset.assetWithURL(sourceURL)
var imageGenerator = AVAssetImageGenerator(asset: asset!)
var time = CMTimeMake(1, 1)
var imageRef = try! imageGenerator!.copyCGImageAtTime(time, actualTime: nil)
var thumbnail = UIImage.imageWithCGImage(imageRef)
CGImageRelease(imageRef) // CGImageRef won't be released by ARC

swift 3.0

var sourceURL = URL(string: "Your Asset URL")
var asset = AVAsset(url: sourceURL!)
var imageGenerator = AVAssetImageGenerator(asset: asset)
var time = CMTimeMake(1, 1)
var imageRef = try! imageGenerator.copyCGImage(at: time, actualTime: nil)
var thumbnail = UIImage(cgImage:imageRef)

Note : Interpret Swift code according to your swift version.

关于objective-c - 在当前时间创建 AVPlayer 的缩略图或图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15360721/

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