参考
AVCaptureSession是AVFoundation的核心类,用于捕捉视频和音频,协调视频和音频的输入和输出流.
设置Session分辨率
- (BOOL)canSetSessionPreset:(AVCaptureSessionPreset)preset;
@property(nonatomic, copy) AVCaptureSessionPreset sessionPreset;
实例:
// 2 设置session显示分辨率
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
[session setSessionPreset:AVCaptureSessionPreset640x480];
else
[session setSessionPreset:AVCaptureSessionPresetPhoto];
给Session添加input输入
#获取session的输入设备
@property(nonatomic, readonly) NSArray<__kindof AVCaptureInput *> *inputs;
- (BOOL)canAddInput:(AVCaptureInput *)input;
- (void)addInput:(AVCaptureInput *)input;
- (void)removeInput:(AVCaptureInput *)input;
实例:
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的开启与停止
AVCaptureSession 最后必须开启才能使用
- (void)startRunning;
- (void)stopRunning;
//是否正在Running
@property(nonatomic, readonly, getter=isRunning) BOOL running;
网友评论