日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

直播的学习与使用-----采集

發布時間:2025/3/8 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 直播的学习与使用-----采集 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

// 捕獲音視頻

- (void)setupCaputureVideo

{

// 1.創建捕獲會話,必須要強引用,否則會被釋放

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

_captureSession = captureSession;

// 2.獲取攝像頭設備,默認是后置攝像頭

AVCaptureDevice *videoDevice = [self getVideoDevice:AVCaptureDevicePositionFront];

// 3.獲取聲音設備

AVCaptureDevice *audioDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];

// 4.創建對應視頻設備輸入對象

AVCaptureDeviceInput *videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:nil];

_currentVideoDeviceInput = videoDeviceInput;

// 5.創建對應音頻設備輸入對象

AVCaptureDeviceInput *audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:nil];

// 6.添加到會話中

// 注意“最好要判斷是否能添加輸入,會話不能添加空的

// 6.1 添加視頻

if ([captureSession canAddInput:videoDeviceInput]) {

[captureSession addInput:videoDeviceInput];

}

// 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 Capture Queue", DISPATCH_QUEUE_SERIAL);

[videoOutput setSampleBufferDelegate:self queue:videoQueue];

if ([captureSession canAddOutput:videoOutput]) {

[captureSession addOutput:videoOutput];

}

// 8.獲取音頻數據輸出設備

AVCaptureAudioDataOutput *audioOutput = [[AVCaptureAudioDataOutput alloc] init];

// 8.2 設置代理,捕獲視頻樣品數據

// 注意:隊列必須是串行隊列,才能獲取到數據,而且不能為空

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];

}

// 9.獲取視頻輸入與輸出連接,用于分辨音視頻數據

_videoConnection = [videoOutput connectionWithMediaType:AVMediaTypeVideo];

// 10.添加視頻預覽圖層

AVCaptureVideoPreviewLayer *previedLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession];

previedLayer.frame = [UIScreen mainScreen].bounds;

[self.view.layer insertSublayer:previedLayer atIndex:0];

_previedLayer = previedLayer;

// 11.啟動會話

[captureSession startRunning];

}

// 指定攝像頭方向獲取攝像頭

- (AVCaptureDevice *)getVideoDevice:(AVCaptureDevicePosition)position

{

NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];

for (AVCaptureDevice *device in devices) {

if (device.position == position) {

return device;

}

}

return nil;

}

#pragma mark - AVCaptureVideoDataOutputSampleBufferDelegate

// 獲取輸入設備數據,有可能是音頻有可能是視頻

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

{

if (_videoConnection == connection) {

NSLog(@"采集到視頻數據");

} else {

NSLog(@"采集到音頻數據");

}

}

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的直播的学习与使用-----采集的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。