Reputation: 918
I'm using the VideoToolbox framework to retrieve data from AVCaptureSession and encode it to h264 and acc.
I'm at a point where I:
func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)
CMSampleBuffer
to CVImageBuffer
and encode it to h264 using VTCompressionSession
which passes the encoded frame in VTCompressionOutputCallback
CMSampleBuffer
to acc and pass it as UnsafeMutableAudioBufferListPointer
.I'm now blocked at a point where I want to correctly convert these streams to bytes of Data
to write to a url through FileHandle
. How should I go about this?
I need to have access to encoded streams before the actual file is finalized so I can't use (I think) AVAssetWriter
to save unencoded streams to an mp4 file because from what I can tell I need to pass unencoded samples to AVAssetWriter
for it to work properly. Or am I mistaken?
Upvotes: 4
Views: 1938
Reputation: 918
Turns out you can save encoded CMSampleBuffer
using AVAssetWriter
but you need to pass nil
as outputSettings in AVAssetWriterInput
to prevent re-encoding data:
let input AVAssetWriterInput(mediaType: mediaType, outputSettings: nil, sourceFormatHint: sourceFormatHint)
Upvotes: 1