Firestore 找不到视频文件,但它在播放器中播放
Posted
技术标签:
【中文标题】Firestore 找不到视频文件,但它在播放器中播放【英文标题】:Firestore cannot find video file but it plays in Player 【发布时间】:2021-05-21 21:10:32 【问题描述】:我正在尝试在上传到 FireStore 之前裁剪视频文件。我使用的代码如下:
func fileOutput(_ output: AVCaptureFileOutput,
didFinishRecordingTo outputFileURL: URL,
from connections: [AVCaptureConnection],
error: Error?)
// Note: Because we use a unique file path for each recording, a new recording won't overwrite a recording mid-save.
isRecording = false
let exportPath = NSTemporaryDirectory().appendingFormat("\(randomString(length: 5)).MOV")
let exportURL = URL(fileURLWithPath: exportPath)
let asset = AVAsset(url: outputFileURL)
let clipVideoTrack = asset.tracks( withMediaType: AVMediaType.video ).first! as AVAssetTrack
let rect = CGRect(x: 0, y: 0, width: clipVideoTrack.naturalSize.height, height: clipVideoTrack.naturalSize.height)
asset.cropVideoTrack(at: 0, cropRect: rect, outputURL: exportURL) result in
switch result
case .success():
self.videoURL = exportURL
self.postPicture(postURL: exportURL)
self.isTaken = true
var success = true
......
这就是我裁剪视频的方式:https://gist.github.com/vakhidbetrakhmadov/1402653b6f3e5ca99923a90ff8763b9c
如果我直接从 didFinishRecording 的 'outputFileURL' 上传视频,没有问题。但是当我使用“exportURL”时它就不起作用了。奇怪的是我可以使用相同的 URL (exportURL) 播放裁剪的视频。这是调试日志:
Post picture to database here
Video to play: file:///private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV
2021-05-21 23:58:12.426620+0300 DogGram[91943:9315533] Body file is unreachable: /private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV
Error Domain=NSCocoaErrorDomain Code=260 "The file “6WYy2.MOV” couldn’t be opened because there is no such file." UserInfo=NSURL=file:///private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV, NSFilePath=/private/var/mobile/Containers/Data/Application/AA73684B-4199-47DB-954A-F6FD5AE3C8B5/tmp/6WYy2.MOV, NSUnderlyingError=0x281102880 Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"
谁能看到我在这里做错了什么?
【问题讨论】:
【参考方案1】:问题是,我在尝试上传的同时将文件保存到库中。我猜ios在保存文件时会锁定文件。我只是轮流做,现在可以了。
【讨论】:
以上是关于Firestore 找不到视频文件,但它在播放器中播放的主要内容,如果未能解决你的问题,请参考以下文章