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:
- obtain data using the delegate method
func captureOutput(_ captureOutput: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)
- convert video
CMSampleBuffer
toCVImageBuffer
and encode it to h264 usingVTCompressionSession
which passes the encoded frame inVTCompressionOutputCallback
- encode audio
CMSampleBuffer
to acc and pass it asUnsafeMutableAudioBufferListPointer
.
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?