0
我使用AVFoundation从相机中捕获CMSampleBufferRef
,然后将其转换为CVPixelBufferRef
以写入视频。我想要做的是修改视频帧内的一些像素。这就是为什么我需要从CMSampleBuffer
中获得CVPixelBufferRef
。我的问题是,我不能在原CMSampleBuffer
的音频数据包括我的新CVPixelBufferRef
带音频的CVPixelBuffer
我也试图重新CMSampleBuffer
与CVPixelBufferRef
但它返回我的错误:
- (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;
}