Getting an error when trying to convert a video recorded from camera or picked from gallery: * 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'`
This is discussed here: CMSampleBufferRef kCMSampleBufferAttachmentKey_TrimDurationAtStart crash
But no resolution was reached.
Here is my code:
[self.audioInput requestMediaDataWhenReadyOnQueue:self.audioQueue usingBlock:^{
CMSampleBufferRef buffer;
LIMTAssetFileWriter * __strong strongSelf = weakSelf;
while (strongSelf.audioInput.isReadyForMoreMediaData) {
LIMTPayload *payload = [strongSelf.cache dequeuePayloadForType:LIMTPayloadTypeAudio];
buffer = payload.getCMSampleBuffer;
if (buffer) {
if (!strongSelf.sessionStarted) {
[strongSelf.assetWriter startSessionAtSourceTime:CMSampleBufferGetPresentationTimeStamp(buffer)];
strongSelf.sessionStarted = YES;
}
[strongSelf.audioInput appendSampleBuffer:buffer];
[LIMTLogger.sharedLogger logInfo:@"Audio buffer appended"];
CFRelease(buffer);
buffer = NULL;
} else if ([strongSelf.cache statusForType:kCMMediaType_Audio] == LIMTCacheStatusCompleted) {
[strongSelf.audioInput markAsFinished];
[LIMTLogger.sharedLogger logInfo:@"Audio complete"];
dispatch_group_leave(strongSelf.dispatchGroup);
break;
} else {
break;
}
}
}];
Error is happening here: [strongSelf.audioInput appendSampleBuffer:buffer];