Я получаю эту ошибку при попытке записи в файл mp4 во время записи с камеры.
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVAssetWriterInput appendSampleBuffer:]
Cannot append sample buffer: First input buffer must have an appropriate kCMSampleBufferAttachmentKey_TrimDurationAtStart since the codec has encoder delay'
Вот код для заливки звука:
- (void)primeAudioForSampleBuffer:(nonnull CMSampleBufferRef)sampleBuffer {
if (self.shouldPrimeAudio && !self.didPrimeAudio) {
CMAttachmentMode attachmentMode;
CFTypeRef trimDuration = CMGetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, &attachmentMode);
if (!trimDuration) {
CMTime primeAudioTime = CMTimeMake(PrimeSampleBufferCount, CMSampleBufferGetDuration(sampleBuffer).timescale);
CFDictionaryRef dict = CMTimeCopyAsDictionary(primeAudioTime, kCFAllocatorDefault);
CMSetAttachment(sampleBuffer, kCMSampleBufferAttachmentKey_TrimDurationAtStart, dict, kCMAttachmentMode_ShouldNotPropagate);
}
self.didPrimeAudio = YES;
}
}
Нет кубиков ... что я делаю не так?