如何将CIImage转换为CMSampleBufferRef

时间:2013-09-17 13:58:21

标签: uiimage avfoundation avcapturesession ciimage cmsamplebufferref

我正在使用AVCapturesession录制视频我在CMSamplbufferRef形式的recrecive示例缓冲区方法中获取。我已将其转换为CIImage并进行了一些更改,现在我想将CIImage转换为CMSampleBufferRef可以任何人请帮我, 我惹了很多,但我没有找到答案,我希望我能在这里找到答案。

1 个答案:

答案 0 :(得分:2)

我没有信用,功劳归于:Crop CMSampleBufferRef

CVPixelBufferRef pixelBuffer;
CVPixelBufferCreate(kCFAllocatorSystemDefault, 640, 480, kCVPixelFormatType_32BGRA, NULL, &pixelBuffer);

CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

CIContext * ciContext = [CIContext contextWithOptions: nil];
[ciContext render:ciImage toCVPixelBuffer:pixelBuffer];
CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );

CMSampleTimingInfo sampleTime = {
    .duration = CMSampleBufferGetDuration(sampleBuffer),
    .presentationTimeStamp = CMSampleBufferGetPresentationTimeStamp(sampleBuffer),
    .decodeTimeStamp = CMSampleBufferGetDecodeTimeStamp(sampleBuffer)
};

CMVideoFormatDescriptionRef videoInfo = NULL;
CMVideoFormatDescriptionCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, &videoInfo);

CMSampleBufferRef oBuf;
CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixelBuffer, true, NULL, NULL, videoInfo, &sampleTime, &oBuf);