【问题标题】:Is there any way to restrict the duration of output of AVAssetWriter in iOS?有什么方法可以限制 iOS 中 AVAssetWriter 的输出持续时间?
【发布时间】:2019-01-04 04:52:10
【问题描述】:

我正在使用 ReplayKit api 捕获视频/音频样本。下面是截屏的sn-p

        recorder.startCapture(handler: {
        (cmSampleBuffer, rpSampleBufferType, error) in
        AssetWriter.shared.write(buffer: cmSampleBuffer, bufferType: rpSampleBufferType)
    }, completionHandler: {
        (error) in
        if let error = error {
            self.isCapturing = false
            NSLog("Error in capturing screens: \(error.localizedDescription)")
        } else {
            self.isCapturing = true
            NSLog("Capturing started successfully.")
        }
        self.updateViewButtons()
    })

并使用 AVAssetWriter 将这些 cmSampleBuffers 转换为电影文件,但我想限制电影文件的大小,如果超过 1 分钟,则仅捕获最后 1 分钟。

【问题讨论】:

  • 你找到解决办法了吗。

标签: avfoundation replaykit


【解决方案1】:

棘手的部分是“只保留最后 1 分钟”;据我所知,没有简单的方法可以做到这一点。所以你最好的选择可能是这样的:

  • 录制时,每分钟启动一个新的 AVAssetWriter,只保留当前和之前的录制内容
  • 当录制完成并开始组装“最后 1 分钟”时
    • AVAssets打开上一个和当前的录音
    • 将这些时间范围插入到新的AVMutableComposition 中,以便记录最后 1 分钟
    • 将带有AVAssetExportSession 的合成导出到最终电影(使用直通预设可以避免重新编码的开销/质量损失)

【讨论】:

    猜你喜欢
    • 2013-11-18
    • 1970-01-01
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2019-12-25
    • 2014-05-15
    • 2023-01-20
    • 1970-01-01
    相关资源
    最近更新 更多