视频相关知识总结

AVFoundation视频流的捕捉:

要捕捉视频需要这几个类:

AVCaptureDevice 代表了输入设备,例如摄像头与麦克风。

AVCaptureInput 代表了输入数据源

AVCaptureOutput 代表了输出数据源

AVCaptureSession 用于协调输入与输出之间的数据流

AVCaptureVideoPreviewLayer   提供摄像头的预览功能

  

具体的步骤:

1.创建AVCaputureSession。

AVCaptureSession * session = [[AVCaptureSession alloc]init];

 

2.创建AVCaptureDevice:

AVCaptureDevice * device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

 

3.创建AVCaptureDeviceInput,并添加到Session中:

 

我们需要使用AVCaptureDeviceInput来让设备添加到session中, AVCaptureDeviceInput负责管理设备端口。我们可以理解它为设备的抽象。一个设备可能可以同时提供视频和音频的捕捉。我们可以分别用AVCaptureDeviceInput来代表视频输入和音频输入。

 

NSError * error;

AVCaptureDeviceInput * input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];

 

4.创建AVCaptureOutput:        线程必须是串行的,确保视频帧按序到达。

AVCaptureVideoDataOutput * output = [[AVCaptureVideoDataOutput alloc]init];

[session addOutput:output];

[output setSampleBufferDelegate:self queue:dispatch_get_global_queue(0, 0)];

 

5.开始捕捉

[session startRunning];

 

6.在AVCaptureVideoDataOutputSampleBufferDelegate代理方法中进行视频流的分析

 

-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

{

 

}

posted @ 2016-12-27 00:25  微凉空间  Views(123)  Comments(0Edit  收藏  举报