Sub*_*ash 8 iphone avfoundation
我正在尝试从数据创建CMSampleBuffer Ref并尝试将其提供给AVAssetWriter.但资产作家未能从数据中创建电影.以下是创建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);
Run Code Online (Sandbox Code Playgroud)
当我们使用从AVFoundation数据输出回调方法获得的原始CMSampleBufferRef时,电影创建工作正常.
但是当我尝试使用自定义CMSampleBufferRef创建影片时,同样失败了.资产编写器抛出以下错误:
The operation couldn’t be completed. (AVFoundationErrorDomain error -11800.)
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.
您应该查看 AVAssetWriterInputPixelBufferAdaptor - 它接受 CVPixelBuffers,因此您不需要在 CMSampleBuffer 中转换 CVPixelBuffer。
这是苹果开发论坛上有关它的主题的链接 -> https://devforums.apple.com/thread/70258?tstart=0
另外 - 您有机会发布您的项目文件或捕获影片工作的示例代码 - 我正在使用 AVFoundation 数据输出回调方法中的默认 CMSampleBuffer - 但是当我将其保存到相机胶卷时,除了最后 5 个之外,它都是黑色的我必须手动擦洗的帧:S
对于我的问题的任何帮助将不胜感激。
干杯,
迈克尔
| 归档时间: |
|
| 查看次数: |
13425 次 |
| 最近记录: |