add duration to onVideoChunkReady data
This commit is contained in:
parent
694d9cfa8c
commit
b006b1e744
@ -351,11 +351,15 @@ public final class CameraView: UIView, CameraSessionDelegate {
|
||||
onInitReady([
|
||||
"filepath": chunk.url.path,
|
||||
])
|
||||
case .data(index: let index):
|
||||
onVideoChunkReady([
|
||||
case let .data(index: index, duration: duration):
|
||||
var data: [String: Any] = [
|
||||
"filepath": chunk.url.path,
|
||||
"index": index,
|
||||
])
|
||||
]
|
||||
if let duration {
|
||||
data["duration"] = duration.seconds
|
||||
}
|
||||
onVideoChunkReady(data)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@ class ChunkedRecorder: NSObject {
|
||||
|
||||
enum ChunkType {
|
||||
case initialization
|
||||
case data(index: UInt64)
|
||||
case data(index: UInt64, duration: CMTime?)
|
||||
}
|
||||
|
||||
struct Chunk {
|
||||
@ -48,7 +48,7 @@ extension ChunkedRecorder: AVAssetWriterDelegate {
|
||||
case .initialization:
|
||||
saveInitSegment(segmentData)
|
||||
case .separable:
|
||||
saveSegment(segmentData)
|
||||
saveSegment(segmentData, report: segmentReport)
|
||||
@unknown default:
|
||||
fatalError("Unknown AVAssetSegmentType!")
|
||||
}
|
||||
@ -60,11 +60,16 @@ extension ChunkedRecorder: AVAssetWriterDelegate {
|
||||
onChunkReady(url: url, type: .initialization)
|
||||
}
|
||||
|
||||
private func saveSegment(_ data: Data) {
|
||||
private func saveSegment(_ data: Data, report: AVAssetSegmentReport?) {
|
||||
let name = "\(chunkIndex).mp4"
|
||||
let url = outputURL.appendingPathComponent(name)
|
||||
save(data: data, url: url)
|
||||
onChunkReady(url: url, type: .data(index: chunkIndex))
|
||||
let duration = report?
|
||||
.trackReports
|
||||
.filter { $0.mediaType == .video }
|
||||
.first?
|
||||
.duration
|
||||
onChunkReady(url: url, type: .data(index: chunkIndex, duration: duration))
|
||||
chunkIndex += 1
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user