參考
AVCaptureSession是AVFoundation的核心類(lèi),用于捕捉視頻和音頻,協(xié)調(diào)視頻和音頻的輸入和輸出流.
設(shè)置Session分辨率
- (BOOL)canSetSessionPreset:(AVCaptureSessionPreset)preset;
@property(nonatomic, copy) AVCaptureSessionPreset sessionPreset;
實(shí)例:
// 2 設(shè)置session顯示分辨率
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
[session setSessionPreset:AVCaptureSessionPreset640x480];
else
[session setSessionPreset:AVCaptureSessionPresetPhoto];
給Session添加input輸入
#獲取session的輸入設(shè)備
@property(nonatomic, readonly) NSArray<__kindof AVCaptureInput *> *inputs;
- (BOOL)canAddInput:(AVCaptureInput *)input;
- (void)addInput:(AVCaptureInput *)input;
- (void)removeInput:(AVCaptureInput *)input;
實(shí)例:
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
isUsingFrontFacingCamera = NO;
if ([session canAddInput:deviceInput]){
[session addInput:deviceInput];
}
給session添加output輸出
@property(nonatomic, readonly) NSArray<__kindof AVCaptureOutput *> *outputs;
- (BOOL)canAddOutput:(AVCaptureOutput *)output;
- (void)addOutput:(AVCaptureOutput *)output;
- (void)removeOutput:(AVCaptureOutput *)output;
Session的開(kāi)啟與停止
AVCaptureSession 最后必須開(kāi)啟才能使用
- (void)startRunning;
- (void)stopRunning;
//是否正在Running
@property(nonatomic, readonly, getter=isRunning) BOOL running;