I am using AVCapturesession to record video I am reciving out at didrecive sample buffer method in the form of CMSamplbufferRef.I Have Converted that to CIImage and made some some change and now I Want to convert that CIImage to CMSampleBufferRef Can Any one please help me, I Broused a lot but I didn't found answer to this any where I hope I'll found it here.
Asked
Active
Viewed 4,224 times
3
-
did you find a solution? does it work for you ?https://stackoverflow.com/a/19916522/7767664 – user924 Mar 01 '18 at 14:02
1 Answers
2
I take no credit, credit goes to :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);