AVFoundationを使用CMSampleBufferRefしてカメラからキャプチャし、それを変換しCVPixelBufferRefてビデオに書き込みます。私がやりたいのは、ビデオフレーム内のいくつかのピクセルを変更することです。だから私CVPixelBufferRefは自分のから抜け出す必要がありますCMSampleBuffer。私の問題は、オリジナルのオーディオデータをCMSampleBuffer新しいものに含めることができなかったことですCVPixelBufferRef
私もで再作成しようとしまし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;
}