在AVCaptureVideoDataOutputSampleBufferDelegate协议方法中: - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection { CVImageBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); CVPixelBufferLockBaseAddress(pixelBuffer, 0); // access the data int width = CVPixelBufferGetWidth(pixelBuffer); int height = CVPixelBufferGetHeight(pixelBuffer); unsigned char *rawPixelBase = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer); // Do something with the raw pixels here CVPixelBufferUnlockBaseAddress(pixelBuffer, 0); AVFrame *pFrame; pFrame = avcodec_alloc_frame(); avpicture_fill((AVPicture*)pFrame, rawPixelBase, PIX_FMT_RGB32, width, height); } 其中 AVFrame和 avcodec_alloc_frame和 avpicture_fill为ffmpeg中的函数.所以需要在把它的头文件加入你的源文件中. |