首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带音频的CVPixelBuffer

带音频的CVPixelBuffer
EN

Stack Overflow用户
提问于 2012-01-29 10:11:57
回答 1查看 1.4K关注 0票数 0

我使用AVFoundation从摄像头捕获CMSampleBufferRef,然后将其转换为CVPixelBufferRef以写入视频。我想做的是修改视频帧内的一些像素。这就是为什么我需要从我的CMSampleBuffer中取出CVPixelBufferRef。我的问题是我不能在我的新CVPixelBufferRef中包含原始CMSampleBuffer的音频数据

我还尝试用CVPixelBufferRef重新创建CMSampleBuffer,但返回错误:

代码语言:javascript
复制
- (CMSampleBufferRef)newModifyImage:(CMSampleBufferRef)sampleBuffer {
    CVImageBufferRef cvimgRef = CMSampleBufferGetImageBuffer(sampleBuffer);
    CVPixelBufferLockBaseAddress(cvimgRef,0);

    uint8_t *buf=(uint8_t *)CVPixelBufferGetBaseAddress(cvimgRef);

    size_t bytesPerRow = CVPixelBufferGetBytesPerRow(cvimgRef); 
    size_t width = CVPixelBufferGetWidth(cvimgRef); 
    size_t height = CVPixelBufferGetHeight(cvimgRef); 


    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, bytesPerRow, NULL, NULL, NULL, &pixelBufRef);

    CMVideoFormatDescriptionRef videoInfo = NULL;

    result = CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixelBufRef, &videoInfo);

    CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBufRef, true, NULL, NULL, videoInfo, &timimgInfo, &newSampleBuffer);
    return newSampleBuffer;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-29 16:19:11

检查RosyWriter示例代码http://developer.apple.com/library/ios/#samplecode/RosyWriter/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40011110

它从样本缓冲区中写入视频和音频

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9050347

复制
相关文章

相似问题

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