尝试转换从相机录制的视频或从图库中选择的视频时出错: * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[AVAssetWriterInput appendSampleBuffer:] 无法附加样本缓冲区:第一个输入缓冲区必须具有适当的kCMSampleBufferAttachmentKey_TrimDurationAtStart 因为编解码器有编码器延迟'`
这在这里讨论:CMSampleBufferRef kCMSampleBufferAttachmentKey_TrimDurationAtStart crash
但没有达成任何决议。
这是我的代码:
[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;
}
}
}];
这里发生错误:[strongSelf.audioInput appendSampleBuffer:buffer];