RTCCVPixelBuffer* remotePixelBuffer = (RTCCVPixelBuffer *)frame.buffer;
CVPixelBufferRef pixelBuffer = remotePixelBuffer.pixelBuffer;
- (instancetype)initWithBuffer:(id<RTCVideoFrameBuffer>)buffer
rotation:(RTCVideoRotation)rotation
timeStampNs:(int64_t)timeStampNs
use that instance method to convert CVPixelBuffer back to RTCVideoFrame.
Hope this information is helpful.
func buffer(from image: CIImage) -> CVPixelBuffer? {
let attrs = [kCVPixelBufferMetalCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue] as CFDictionary
var pixelBuffer : CVPixelBuffer?
let status = CVPixelBufferCreate(kCFAllocatorDefault, Int(image.extent.width), Int(image.extent.height), kCVPixelFormatType_32BGRA, attrs, &pixelBuffer)
guard (status == kCVReturnSuccess) else {
return nil
}
return pixelBuffer
}
If you are going to use it in the Metal framework, then, make sure to put kCVPixelBufferMetalCompatibilityKey: kCFBooleanTrue in the attrs dictionary.
One thing to notice is that in the emulator I received RTCI420Buffers but in the real device I got RTCCVPixelBuffer. Unfortunately, somehow the RTCCVPixelBuffer is not compatible with the Metal view I'm using along with some video effects I'm currently using.
Hope it's helpfull!