iOS 音视频学习-AVFoundation
2020-03-21 本文已影响0人
那些喧嚣
AVFoundation常用类
- 捕捉会话:AVCaptureSession
- 捕捉设备:AVCaptureDevice
- 捕捉设备输入:AVCaptureDeviceInput
- 捕捉设备输出:AVCaptureOutput
AVCaptureOutput子类:
- AVCaptureStillmageOutput
- AVCaptureMovieFileOutput
- AVCaptureAudioDataOutput
- AVCaptureVideoDataOutput
- 捕捉连接:AVCaptureConnection
- 捕捉预览:AVCaputreVideoPreviewLayer
CameraController类
设置Session
- 初始化会话类AVCaptureSession
- 初始化视频/音频设备(前置、后置摄像头)AVCaptureDevice
AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
- 初始化视频/音频输入设备AVCaptureDeviceInput
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:error];
- 把音视频输入设备加入会话captureSession(加入之前判断是否能加入)
- 开启一条异步线程,准备使用
开启captureSession
- 判断是否在运行
- 添加运行
//检查是否处于运行状态
if (![self.captureSession isRunning])
{
//使用同步调用会损耗一定的时间,则用异步的方式处理
dispatch_async(self.videoQueue, ^{
[self.captureSession startRunning];
});
}
关闭captureSession
- 判断是否在运行
- 关闭运行
//检查是否处于运行状态
if ([self.captureSession isRunning])
{
dispatch_async(self.videoQueue, ^{
[self.captureSession stopRunning];
});
}