3

我正在使用 AVCapturesession 录制视频我以 CMSamplbufferRef 的形式在 didrecive 样本缓冲区方法中接收。我已将其转换为 CIImage 并进行了一些更改,现在我想将该 CIImage 转换为 CMSampleBufferRef 任何人都可以帮助我,我很烦恼,但我没有在任何地方找到答案,我希望我能在这里找到它。

4

1 回答 1

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);
于 2013-11-11T21:42:01.143 回答