2016-11-26 123 views
0

我想從視頻中抓取一幀。使用AVAsset時無法完成操作?

但copyCGImageAtTime(在AVAssetImageGenerator)失敗,此錯誤:

The operation could not be completed

當我指定無效的路徑,它拋出不同的錯誤,所以看起來它不是路徑問題。

我想用MP4文件。也許這是一個問題?

import Cocoa 
import AVFoundation 

var asset = AVAsset.init(URL: NSURL.init(fileURLWithPath: "/Users/gippeumi/test.mp4")) 
var assetGen = AVAssetImageGenerator(asset: asset) 
assetGen.appliesPreferredTrackTransform = true 
var tim = CMTimeMakeWithSeconds(0.0, 1) 
do { 
    var img = try assetGen.copyCGImageAtTime(tim, actualTime: nil) 
} catch let error as NSError { 
    // (Printing error here...) 
} 

回答

0

「該錯誤可能是由於使用URLWithString。我認爲您應該使用-fileURLWithPath而不是URLWithString。」

你可以檢查這個鏈接,也許它可以幫助你。

Extract thumbnail from video url

+0

它沒有在操場上工作,但在實際項目上,它的工作原理。我嘗試了很多次,但從未失敗過。 – Gippeumi

相關問題