首先要设置输出格式:
[videoOut setVideoSettings:[NSDictionary dictionaryWithObject:
[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange] forKey:(NSString*)kCVPixelBufferPixelFormatTypeKey]];
在回调中:
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(pixelBuffer, 0);
void *baseAddress = CVPixelBufferGetBaseAddressOfPlane(pixelBuffer,0);
CVPixelBufferUnlockBaseAddress(pixelBuffer, 0);
}
baseAddress就是yuv数据的地址,注意,用CVPixelBufferGetBaseAddress获取的并不是