ios - 无法从照片库中压缩 .mp4 视频

标签 ios swift video compression avurlasset

谁能帮我解决这个问题,压缩视频时出错,例如:

NSLocalizedFailureReason=发生未知错误(-12780)

   let destinationPath =  NSURL(string: VideoFilePath)!     
   let sourceAsset = AVURLAsset(url: inputURL as URL, options: nil)

    let assetExport: AVAssetExportSession = AVAssetExportSession(asset: sourceAsset, presetName: AVAssetExportPresetLowQuality)!
    assetExport.outputFileType = AVFileTypeQuickTimeMovie
    assetExport.outputURL = savePathUrl as URL
    assetExport.exportAsynchronously { () -> Void in

        switch assetExport.status {
        case AVAssetExportSessionStatus.completed:
            DispatchQueue.main.async {
                do {
                    let videoData = try NSData(contentsOf: savePathUrl as URL, options: NSData.ReadingOptions())
                   // self.sendVideoMessage(sender: self.appDelegate.xmppStream!, vidoeData: videoData as NSData, senderJID: self.rosterInfo.jid!,duration: assetExport.asset.duration)

                } catch {
                    print(error)
                }
            }
        case  AVAssetExportSessionStatus.failed:
            print("failed \(assetExport.error)")
        case AVAssetExportSessionStatus.cancelled:
            print("cancelled \(assetExport.error)")
        default:
            print("Task Done")
        }
    }

最佳答案

这样使用:

替换

let destinationPath =  NSURL(string: VideoFilePath)!     

let destinationPath =  NSURL(fileURLPath: VideoFilePath)!     

关于ios - 无法从照片库中压缩 .mp4 视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41952715/

相关文章:

ios - Swift 3 通用参数

ios - 隐式展开的可选字符串的确切用途是什么

c++ - 标准化直方图?

objective-c - 如何从 NSArray 获取元素

ios - 我应该什么时候创建新队列?

swift - 'UnsafePointer<UInt8>' 的初始化导致悬空指针

c# - 使用 C# 从静止图像创建 MJPEG 视频

jquery - 使用Giggle JS在Firefox中无法进行音频/视频通话

ios - 将 slider 值设置为 TextView 中的当前阅读位置

ios - AvCaptureSession代码提取错误