没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![thumb](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/release/download_crawler_static/12789148/bg1.jpg)
零基础学习零基础学习iOS直播之采集直播之采集
直播的采集由采集的设备(摄像头、话筒)不同分为视频采集和音频采集,本篇文章会分别介绍,需要的朋友一起来看下吧
直播的采集由采集的设备(摄像头、话筒)不同分为视频采集和音频采集,本篇文章会分别介绍。
1.采集步骤采集步骤
1. 创建捕捉会话(AVCaptureSession),iOS调用相机和话筒之前都需要创建捕捉对话,把输入输出设备添加进对话中。
2. 往会话中添加视频输入对象(AVCaptureDeviceInput)。
3. 往会话中添加音频输入对象(AVCaptureDeviceInput)。
4. 往会话中添加视频输出对象(AVCaptureVideoDataOutput)。
5. 往会话中添加音频输出对象(AVCaptureAudioDataOutput)。
6. 添加视屏预览图层(AVCaptureVideoPreviewLayer)。
7. 开启会话。
8. 推流(以后讲)。
2.效果图效果图
这是后置摄像头采集的,直播一般用前置摄像头的,但是我实在没勇气放出我的自拍。
3.代码演示代码演示
// 采集
- (void)setupCaputureVideo {
// 1.创建捕获对话,必须要强引用,否则会释放
_captureSession = [[AVCaptureSession alloc] init];
// 2.捕获摄像头设备,默认前置摄像头
AVCaptureDevice *videoDevice = [self getVideoDevice:AVCaptureDevicePositionFront];
// 3.获取声音设备
AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
// 4.创建对应视频设备输入对象
_currentVideoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
// 5.创建对应音频设备输入对象
AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];
// 6.添加到会话中 注意:最好要判断是否能添加输入,会话不能添加空的
// 6.1 添加视频
if ([_captureSession canAddInput:_currentVideoDeviceInput]) {
[_captureSession addInput:_currentVideoDeviceInput];
}
// 6.2 添加音频
if ([_captureSession canAddInput:audioDeviceInput]) {
[_captureSession addInput:audioDeviceInput];
}
// 7.捕获视频数据输出设备
AVCaptureVideoDataOutput *videoOutput = [[AVCaptureVideoDataOutput alloc] init];
//7.1 设置代理, 捕获视频样品数据
dispatch_queue_t videoQueue = dispatch_queue_create("Video Capure Queue", DISPATCH_QUEUE_SERIAL);
[videoOutput setSampleBufferDelegate: self queue:videoQueue];
// 8.设置音频数据输出设备
AVCaptureAudioDataOutput *audioOutput = [[AVCaptureAudioDataOutput alloc] init];
// 8.1 设置代理,捕获音频样品数据 注意:必须是串行队列才能捕获到数据,而且不能为空
dispatch_queue_t audioQueue = dispatch_queue_create("Audio Capure Queue", DISPATCH_QUEUE_SERIAL);
[audioOutput setSampleBufferDelegate:self queue:audioQueue];
// 9.添加到会话中 注意:最好要判断是否能添加输入,会话不能添加空的
if ([_captureSession canAddOutput:videoOutput]) {
[_captureSession addOutput:videoOutput];
}
if ([_captureSession canAddOutput:audioOutput]) {
[_captureSession addOutput:audioOutput];
}
// 10.获取视屏输入与输出连接,用于分辨音视频数据
_videoConnection = [videoOutput connectionWithMediaType:AVMediaTypeVideo];
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
weixin_38646706
- 粉丝: 4
- 资源: 1005
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)