我正在尝试从数据创建CMSampleBuffer引用,并尝试将其提供给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创建电影时,同样会失败。Asset writer抛出以下错误:
The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)请帮我解决这个问题。
发布于 2010-10-03 22:22:47
您应该查看AVAssetWriterInputPixelBufferAdaptor -它接受CVPixelBuffers,因此您不需要将CVPixelBuffer转换为CMSampleBuffer。
这里是苹果开发论坛-> https://devforums.apple.com/thread/70258?tstart=0上关于它的一篇文章的链接。
还有--你有没有可能发布你的项目文件或者捕获电影的示例代码--我使用的是来自AVFoundation数据输出回调方法的默认CMSampleBuffer --但是当我将它保存到相机胶卷时,它是黑色的,除了最后5帧,我必须手动擦除到:S
任何关于我的问题的帮助都将不胜感激。
干杯,
迈克尔
发布于 2014-04-19 11:54:17
The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)对于此错误,它总是在timingInfo无效时发生。它需要使用PTS和Duration将其设置为有效值。
CMSampleTimingInfo timingInfo = kCMTimingInfoInvalid;
timingInfo.presentationTimeStamp = pts;
timingInfo.duration = duration;https://stackoverflow.com/questions/3788231
复制相似问题