簡體   English   中英

如何在 iOS 上將編碼的 CMSampleBuffer 樣本保存到 mp4 文件

[英]How to save encoded CMSampleBuffer samples to mp4 file on iOS

我正在使用 VideoToolbox 框架從 AVCaptureSession 檢索數據並將其編碼為 h264 和 acc。

我正處於以下狀態:

  1. 使用委托方法獲取數據func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)
  2. 將視頻CMSampleBuffer轉換為CVImageBuffer並使用VTCompressionSession將其編碼為 h264, VTCompressionSessionVTCompressionOutputCallback傳遞編碼幀
  3. 將音頻CMSampleBuffer編碼為 acc 並將其作為UnsafeMutableAudioBufferListPointer傳遞。

我現在被阻止,我想正確地將這些流轉換為Data字節以通過FileHandle寫入 url 。 我應該怎么做?

我需要最終確定實際文件之前訪問編碼流所以我不能使用(我認為) AVAssetWriter將未編碼的流保存到 mp4 文件中,因為據我所知,我需要將未編碼的樣本傳遞給AVAssetWriter以便它好好工作。 還是我錯了?

原來你可以使用AVAssetWriter保存編碼的CMSampleBuffer但你需要在AVAssetWriterInput傳遞nil作為AVAssetWriterInput以防止重新編碼數據:

let input AVAssetWriterInput(mediaType: mediaType, outputSettings: nil, sourceFormatHint: sourceFormatHint)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM