一刻剥、采集設(shè)備
1.iphone/ipad? 攝像頭
2.屏幕采集
二滩字、視頻采集方案
1.使用蘋果提供AVFoundation框架進(jìn)行采集
采集步驟:
1.創(chuàng)建捕獲會(huì)話,必須要強(qiáng)引用,否則會(huì)被釋放 (采集數(shù)據(jù)需要新建一個(gè)采集會(huì)話麦箍,且該會(huì)話必須強(qiáng)引用,否則會(huì)被釋放)
??? AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
??? _captureSession = captureSession;
2.尋找相關(guān)所需設(shè)備
? ? AVCaptureDevice *videoDevice = [self getVideoDevice:AVCaptureDevicePositionFront]
?? AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
3.基于輸入設(shè)備生成輸入對(duì)象享钞,并添加到會(huì)話
? ? AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];
? ? AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];????
??? if ([captureSession canAddInput:videoDeviceInput]){
? ? ? ? [captureSession addInput:videoDeviceInput];
? ? }
? ? if ([captureSession canAddInput:audioDeviceInput]) {
? ? ? ? [captureSession addInput:audioDeviceInput];
? ? }
4.創(chuàng)建輸出對(duì)象并添加到會(huì)話
? ? AVCaptureVideoDataOutput *videoOutput = [[AVCaptureVideoDataOutput alloc] init];
? ? // 注意:隊(duì)列必須是串行隊(duì)列诀蓉,才能獲取到數(shù)據(jù),而且不能為空渠啤,原因參考接口說(shuō)明
? ? dispatch_queue_t videoQueue = dispatch_queue_create("Video Capture Queue", DISPATCH_QUEUE_SERIAL);
? // 設(shè)置代理,捕獲視頻樣品數(shù)據(jù)
? ? [videoOutput setSampleBufferDelegate:self queue:videoQueue];
? ? if ([captureSession canAddOutput:videoOutput]) {
? ? ? ? [captureSession addOutput:videoOutput];
? ? }
dispatch_queue_t audioQueue = dispatch_queue_create("Audio Capture Queue", DISPATCH_QUEUE_SERIAL);
// 設(shè)置代理处坪,捕獲音頻樣品數(shù)據(jù)
? ? [audioOutput setSampleBufferDelegate:self queue:audioQueue];
? ? if ([captureSession canAddOutput:audioOutput]) {
? ? ? ? [captureSession addOutput:audioOutput];
? ? }
? ? AVCaptureAudioDataOutput *audioOutput = [[AVCaptureAudioDataOutput alloc] init];
? ? dispatch_queue_t audioQueue = dispatch_queue_create("Audio Capture Queue", DISPATCH_QUEUE_SERIAL);
? ? [audioOutput setSampleBufferDelegate:self queue:audioQueue];
? ? if ([captureSession canAddOutput:audioOutput]) {
? ? ? ? [captureSession addOutput:audioOutput];
? ? }
5.啟動(dòng)會(huì)話
??? [captureSession startRunning];
6.獲取輸入設(shè)備數(shù)據(jù)架专,有可能是音頻有可能是視頻
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
//數(shù)據(jù)保存于sampleBuffer中
? ? if (_videoConnection == connection) {
? ? ? ? NSLog(@"采集到視頻數(shù)據(jù)");
? ? } else {
? ? ? ? NSLog(@"采集到音頻數(shù)據(jù)");
? ? }
}
demo鏈接 參考文章http://www.reibang.com/p/c71bfda055fa