【问题标题】:The operation could not be completed when using AVAsset?使用 AVAsset 时无法完成操作?
【发布时间】:2016-11-26 04:51:27
【问题描述】:

我正在尝试从视频中抓取一帧。

但 copyCGImageAtTime(在 AVAssetImageGenerator 中)失败并出现此错误:

操作无法完成

当我指定无效路径时,它会抛出不同的错误,所以看起来它不是路径问题。

我正在尝试使用 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...)
}

【问题讨论】:

    标签: swift avfoundation


    【解决方案1】:

    “错误可能是由于使用了 URLWithString。我认为您应该使用 -fileURLWithPath 而不是 URLWithString。”

    你可以看看这个链接,也许对你有帮助。

    Extract thumbnail from video url

    【讨论】:

    • 它在操场上不起作用,但在实际项目中,它起作用了。我尝试了很多次,但从未失败过。
    猜你喜欢
    • 2014-10-22
    • 2019-05-27
    • 2013-10-31
    • 2013-07-25
    • 2012-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多