AVFoundation捕捉的核心是AVCaptureSession,官方文档的描述是<code>You use an AVCaptureSession object to coordinate the flow of data from AV input devices to outputs.</code>,可以有多个输入或输出。它是连接AVCaptureInput和AVCaptureOutput的桥梁,它协调input到output之间传输数据。
初始化方法
AVCaptureSession *seesion = [[AVCaptureSession alloc] init];
seesion.sessionPreset = AVCaptureSessionPresetHigh;
属性
/*!
@property sessionPreset
@abstract
Indicates the session preset currently in use by the receiver.
@discussion
The value of this property is an NSString (one of AVCaptureSessionPreset*) indicating
the current session preset in use by the receiver. The sessionPreset property may be set
while the receiver is running.
*/
@property(nonatomic, copy) NSString *sessionPreset;```
默认值是<code>
AVCaptureSessionPresetHigh</code>
当然还有其他值
AVCaptureSessionPreset1280x720
AVCaptureSessionPreset1920x1080
AVCaptureSessionPreset352x288
AVCaptureSessionPreset640x480
AVCaptureSessionPresetInputPriority
AVCaptureSessionPresetLow
AVCaptureSessionPresetMedium
AVCaptureSessionPresetPhoto
AVCaptureSessionPresetiFrame1280x720
AVCaptureSessionPresetiFrame960x540
![Paste_Image.png](https://img.haomeiwen.com/i1643663/52024bd809520a33.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##一些方法
若想在一个已经使用上的session中(已经startRunning了)做更换新的device、删除旧的device等一系列操作,(比如可以通过调用下面两个方法切换手机的摄像头操作)那么就需要使用如下方法:
/*!
@method beginConfiguration
@abstract
When paired with commitConfiguration, allows a client to batch multiple configuration
operations on a running session into atomic updates.
@discussion
-beginConfiguration / -commitConfiguration are AVCaptureSession's mechanism
for batching multiple configuration operations on a running session into atomic
updates. After calling [session beginConfiguration], clients may add or remove
outputs, alter the sessionPreset, or configure individual AVCaptureInput or Output
properties. All changes will be pended until the client calls [session commitConfiguration],
at which time they will be applied together. -beginConfiguration / -commitConfiguration
pairs may be nested, and will only be applied when the outermost commit is invoked.
*/
- (void)beginConfiguration;
/*!
@method commitConfiguration
@abstract
When preceded by beginConfiguration, allows a client to batch multiple configuration
operations on a running session into atomic updates.
*/
- (void)commitConfiguration;
/*!
@method stopRunning
@abstract
Starts an AVCaptureSession instance running
*/
- (void)startRunning;
/*!
@method stopRunning
@abstract
Stops an AVCaptureSession instance that is currently running.
*/
- (void)stopRunning;
网友评论