0

我正在使用 AVFoundationCMSampleBufferRef从相机捕获,然后将其转换CVPixelBufferRef为写入视频。我想要做的是修改视频帧内的一些像素。这就是为什么我需要CVPixelBufferRef摆脱我的CMSampleBuffer. 我的问题是我无法将原始的音频数据包含CMSampleBuffer到我的新的CVPixelBufferRef

我也尝试重新创建CMSampleBufferCVPixelBufferRef但它返回错误:

- (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;
}
4

1 回答 1

1

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

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

于 2012-01-29T08:19:11.250 回答