I am writing an MP4 file from a video recording.
I'd like to understand how large this file is getting during the recording itself so that I can warn the user if the file is close to exceeding the amount of available space on the device.
Is there a way to do this prior to finishing writing the file? I understand that AVCaptureFileOutput
has a maxRecordedFileSize
(which would obviate the need for me to estimate the file size in the first place) but I have to use AVAssetWriter
in this case since I need access to the individual frames' sample buffers during the recording for some real-time image processing.
One attempt I've made is to try calling CMSampleBufferGetTotalSampleSize()
on each audio and video sample buffer that is successfully appended to its corresponding AVAssetWriterInput
, and add these up. However, the resulting size is 10x smaller than what I get if I check FileManager.default.fileSize(atPath:)
after the file has finished writing.
Are there any other options here?