首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从数据创建CMSampleBufferRef

从数据创建CMSampleBufferRef
EN

Stack Overflow用户
提问于 2010-09-24 22:49:54
回答 2查看 14.2K关注 0票数 8

我正在尝试从数据创建CMSampleBuffer引用,并尝试将其提供给AVAssetWriter。但asset writer无法根据数据创建电影。以下是创建CMSampleBufferRef的代码。

代码语言:javascript
运行
复制
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抛出以下错误:

代码语言:javascript
运行
复制
The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)

请帮我解决这个问题。

EN

回答 2

Stack Overflow用户

发布于 2010-10-03 22:22:47

您应该查看AVAssetWriterInputPixelBufferAdaptor -它接受CVPixelBuffers,因此您不需要将CVPixelBuffer转换为CMSampleBuffer。

这里是苹果开发论坛-> https://devforums.apple.com/thread/70258?tstart=0上关于它的一篇文章的链接。

还有--你有没有可能发布你的项目文件或者捕获电影的示例代码--我使用的是来自AVFoundation数据输出回调方法的默认CMSampleBuffer --但是当我将它保存到相机胶卷时,它是黑色的,除了最后5帧,我必须手动擦除到:S

任何关于我的问题的帮助都将不胜感激。

干杯,

迈克尔

票数 4
EN

Stack Overflow用户

发布于 2014-04-19 11:54:17

代码语言:javascript
运行
复制
    The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)

对于此错误,它总是在timingInfo无效时发生。它需要使用PTSDuration将其设置为有效值。

代码语言:javascript
运行
复制
CMSampleTimingInfo timingInfo = kCMTimingInfoInvalid;
timingInfo.presentationTimeStamp = pts; 
timingInfo.duration = duration;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3788231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档