从数据创建CMSampleBufferRef [英] Creating CMSampleBufferRef from the data

查看:128
本文介绍了从数据创建CMSampleBufferRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数据创建CMSampleBuffer Ref并尝试将其提供给AVAssetWriter。
但资产编辑无法从数据创建电影。以下是创建CMSampleBufferRef的代码。

I am trying to create a CMSampleBuffer Ref from the data and trying to feed it to AVAssetWriter. But asset writer is failing to create the movie from the data. Following is the code to create the 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时,电影创作工作正常。

Movie creation works fine when we use the original CMSampleBufferRef obtained from the AVFoundation data output callback method.

但是当我尝试使用自定义CMSampleBufferRef创建电影时,同样失败。资产编写器抛出以下错误:

But the same fails when I try to create the movie using the custom CMSampleBufferRef. Asset writer throws the following error:

The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)

请帮我解决此问题。

推荐答案

你应该研究AVAssetWriterInputPixelBufferAdaptor - 它接受CVPixelBuffers,因此你不需要在CMSampleBuffer中转换CVPixelBuffer。

You should look into AVAssetWriterInputPixelBufferAdaptor - it accepts CVPixelBuffers so you don't need to convert the CVPixelBuffer in a CMSampleBuffer.

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

here is a link to a thread about it on the apple dev forum -> https://devforums.apple.com/thread/70258?tstart=0

此外 - 您有可能发布项目文件或捕获影片工作的示例代码 - 我正在使用AVFoundation数据输出回调方法中的默认CMSampleBuffer - 但是当我将其保存到相机胶卷时,除了我必须手动擦除的最后5帧之外,它都是黑色的:S

Also - any chance you could post your project file or sample code of the capture movie working -- I am using the default CMSampleBuffer from the AVFoundation data output callback method - but when I save it to camera roll it is all black except the last 5 frames which I have to manually scrub to :S

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

any help in regards to my issue would be greatly appreciated.

干杯,

Michael

这篇关于从数据创建CMSampleBufferRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆