我正在使用LPCM中的AVFoundation录制音频,然后根据时间将其分成多个块。
我遇到了几种不同的分割方法:
以AVAsset
处理记录,然后使用
AVAssetExportSession
或几个(请参见下文)。
仅根据记录的数量对记录的原始二进制文件进行分块 样本,例如在this question的公认答案中。
AVAssetExportSession
有点面向视频,按照我的看法,我需要为每个块创建一个单独的导出会话。我对此很担心,坦率地说,这使我深入到了回调地狱。
我目前拥有的是类似此伪代码的东西:
currentAsset!.loadValuesAsynchronously(forKeys: ["exportable"]) {
if status is ok {
export()
}
}
func export() {
for chunk in chunks {
exportChunk(chunkTime)
}
}
func exportChunk() {
if let exporter = AVAssetExportSession(asset: currentAsset!, presetName: AVAssetExportPresetPassthrough) {
// set exporter parameters
exporter.exportAsynchronously(completionHandler: {
// check status, update progress etc.
}
}
}
基于样本进行分块似乎很简单。我想我可以轻松地将其划分为GCD串行队列。
有什么问题吗?有什么我想念的吗?您将如何处理?