• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 共享扩展中的 AVAssetExportSession

[复制链接]
菜鸟教程小白 发表于 2022-12-12 20:07:43 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试在共享扩展中选择的视频上使用 AVAssetExportSession 并获取

Error Domain=NSURLErrorDomain Code=-3000 "Cannot create file" UserInfo={NSLocalizedDescription=Cannot create file, NSUnderlyingError=0x14811fdb0 {Error Domain=NSOSStatusErrorDomain Code=-12124 "(null)"}}

但是我可以在同一个 NSURL 上手动创建文件而不会出错。这是我正在使用的功能

func reencodeVideo() {
    let videoAsset = AVURLAsset(URL: video.url)

    let videoTrack = videoAsset.tracksWithMediaType(AVMediaTypeVideo)[0] as AVAssetTrack
    print(videoTrack.estimatedDataRate)
    let exportSession = AVAssetExportSession(asset: videoAsset, presetName: AVAssetExportPreset1920x1080)
    guard let outputURL = uploadableFileURL else {
        return
    }
    let fileManager = NSFileManager.defaultManager()
    // let created = fileManager.createFileAtPath(outputURL.path!, contents: nil, attributes: nil)
    if let path = outputURL.path where fileManager.fileExistsAtPath(path) {
        print("file exists")
    }
    do {
        try fileManager.removeItemAtURL(outputURL)
        print("deleted")
    } catch {
        print(error)
    }
    exportSession?.outputURL = outputURL
    exportSession?.outputFileType = AVFileTypeQuickTimeMovie

    exportSession?.exportAsynchronouslyWithCompletionHandler{
        print(exportSession?.status)
    }
}

private var uploadableFileURL: NSURL? {
    guard let tempFileName = video.url.lastPathComponent else {
        return nil
    }
    let fileManager = NSFileManager.defaultManager()
    guard let containerURL = fileManager.containerURLForSecurityApplicationGroupIdentifier(Constants.appGroupIdentifier) else {
        return nil
    }
    return containerURL.URLByAppendingPathComponent("videoFile.mov")
}

我已在同一目录中成功创建文件,但 AVAssetExportSession 在那里返回错误。 任何想法我做错了什么?

我尝试使用 AVAssetReaderAVAssetWriter,而 AVAssetWriter 在尝试启动时返回相同的错误。如果我使用 Documents 目录,则编码过程成功完成,并且仅在使用共享应用程序组容器时失败。



Best Answer-推荐答案


您的问题可能与使用文档文件夹和 icloud 同步有关。 见 https://forums.developer.apple.com/message/77495#77495

如果你这样做:

guard let containerURL = fileManager.containerURLForSecurityApplicationGroupIdentifier(Constants.appGroupIdentifier) else {
        return nil
}

let libraryURL = containerURL.URLByAppendingPathComponent("Library", isDirectory: true)
let cachesURL = libraryURL.URLByAppendingPathComponent("Caches", isDirectory: true)
return cachesURL.URLByAppendingPathComponent("videoFile.mov")

关于ios - 共享扩展中的 AVAssetExportSession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37427804/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap