我正在尝试从数据创建CMSampleBufferRef,并尝试将其提供给AVAssetWriter。但是,asset writer无法从数据创建电影。以下是创建CMSampleBufferRef的代码。
CVImageBufferRef cvimgRef = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(cvimgRef,0);
uint8_t *buf=(uint8_t *)CVPixelBufferGetBaseAddress(cvimgRef);
int width = 480;
int height = 360;
int bitmapBytesPerRow = width*4;
int bitmapByteCount = bitmapBytesPerRow*height;
CVPixelBufferRef pixelBufRef = NULL;
CMSampleBufferRef newSampleBuffer = NULL;
CMSampleTimingInfo timimgInfo = kCMTimingInfoInvalid;
CMSampleBufferGetSampleTimingInfo(sampleBuffer, 0, &timimgInfo);
OSStatus result = 0;
OSType pixFmt = CVPixelBufferGetPixelFormatType(cvimgRef);
CVPixelBufferCreateWithBytes(kCFAllocatorDefault, width, height, pixFmt, buf, bitmapBytesPerRow, NULL, NULL, NULL, &pixelBufRef);
CMVideoFormatDescriptionRef videoInfo = NULL;
result = CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixelBufRef, &videoInfo);
CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBufRef, true, NULL, NULL, videoInfo, &timimgInfo, &newSampleBuffer);
当我们使用从AVFoundation数据输出回调方法获得的原始CMSampleBufferRef时,电影创建工作正常。
但是,当我尝试使用自定义CMSampleBufferRef创建电影时,相同的操作会失败。资产编写器会抛出以下错误:
The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)
请帮我解决这个问题。