如何在swift中实现AVAssetImageGenerator.copyCGImageAtTime

前端之家收集整理的这篇文章主要介绍了如何在swift中实现AVAssetImageGenerator.copyCGImageAtTime前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
到目前为止,我有以下几点
let assetUrl = NSURL.URLWithString(self.targetVideoString)
  let asset: AVAsset = AVAsset.assetWithURL(assetUrl) as AVAsset
  let imageGenerator = AVAssetImageGenerator(asset: asset);
  let time : CMTime = CMTimeMakeWithSeconds(1.0,1)
  let actualTime : CMTime
  let myImage: CGImage =imageGenerator.copyCGImageAtTime(requestedTime: time,actualTime:actualTime,error: <#NSErrorPointer#>)

最后一行是我迷路的地方……我只是想在1.0秒时抓到一张图片

函数声明为
func copyCGImageAtTime(requestedTime: CMTime,actualTime: UnsafeMutablePointer<CMTime>,error outError: NSErrorPointer) -> CGImage!

你必须传递(初始化)CMTime和NSError?变量为“in-out expression”与&amp ;:

let assetUrl = NSURL(string: ...)
let asset: AVAsset = AVAsset.assetWithURL(assetUrl) as AVAsset
let imageGenerator = AVAssetImageGenerator(asset: asset);
let time = CMTimeMakeWithSeconds(1.0,1)

var actualTime : CMTime = CMTimeMake(0,0)
var error : NSError?
let myImage = imageGenerator.copyCGImageAtTime(time,actualTime: &actualTime,error: &error)

还要注意你的第一行

let assetUrl = NSURL.URLWithString(self.targetVideoString)

使用当前的Xcode 6.1不再编译.

原文链接:https://www.f2er.com/swift/319022.html

猜你在找的Swift相关文章