我尝试将mp4文件上传到Firebase,但我收到了此回复:
错误域= FIRStorageErrorDomain代码= -13000"发生未知错误,请检查服务器响应。" UserInfo = {object = video / viedo.mp4,bucket = ********。appspot.com,ResponseBody =无法完成上传。当前尺寸为1385472.预计最终尺寸为1596602。
上传mov文件时没有任何问题。这可以与我上传mp4文件之前的事实有关,我使用AVURLAsset以编程方式在MOV to Mp4 video conversion iPhone Programmatically中创建它(转换是正常的,因为我使用AVPlayer观看文件)?
编辑:从mov文件
创建mp4文件的函数的代码private func encodeVideo(videoURL: URL, completion: @escaping (_ url: URL?) -> ()) {
let avAsset = AVURLAsset(url: videoURL, options: nil)
//Create Export session
exportSession = AVAssetExportSession(asset: avAsset, presetName: AVAssetExportPresetPassthrough)
if exportSession == nil {
return
}
let documentsDirectory2 = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
let filePath = documentsDirectory2.appendingPathComponent("rendered-Video.mp4")
deleteFile(filePath: filePath)
exportSession!.outputURL = filePath
exportSession!.outputFileType = AVFileTypeMPEG4
exportSession!.shouldOptimizeForNetworkUse = true
let start = CMTimeMakeWithSeconds(0.0, 0)
let range = CMTimeRangeMake(start, avAsset.duration)
exportSession!.timeRange = range
exportSession!.exportAsynchronously(completionHandler: {() -> Void in
switch self.exportSession!.status {
case .failed:
completion(nil)
print("%@",self.exportSession!.error ?? "error saving mp4")
case .cancelled:
completion(nil)
print("Export canceled")
case .completed:
completion(filePath)
default:
completion(nil)
break
}
})
}
我有时也会得到反对
ResponseBody =无法完成上传。当前尺寸为1854819.预计最终尺寸为1626331。