我正在使用AVCapturesession录制视频,我在didrecive sample buffer方法中以CMSamplbufferRef的形式接收输出。我已将其转换为CIImage并进行了一些更改,现在我想将该CIImage转换为CMSampleBufferRef。是否有人可以帮助我, 我浏览了很多但没有找到答案,希望能在这里找到。
我正在使用AVCapturesession录制视频,我在didrecive sample buffer方法中以CMSamplbufferRef的形式接收输出。我已将其转换为CIImage并进行了一些更改,现在我想将该CIImage转换为CMSampleBufferRef。是否有人可以帮助我, 我浏览了很多但没有找到答案,希望能在这里找到。
我并不是原作者,感谢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);
render
以避免占用过多的CPU资源。 - famfamfam