AVFoundation捕捉的核心是AVCaptureSession,官方文檔的描述是<code>You use an AVCaptureSession object to coordinate the flow of data from AV input devices to outputs.</code>,可以有多個輸入或輸出郭卫。它是連接AVCaptureInput和AVCaptureOutput的橋梁,它協(xié)調(diào)input到output之間傳輸數(shù)據(jù)铲汪。
初始化方法
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](http://upload-images.jianshu.io/upload_images/1643663-52024bd809520a33.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
##一些方法
若想在一個已經(jīng)使用上的session中(已經(jīng)startRunning了)做更換新的device、刪除舊的device等一系列操作塑悼,(比如可以通過調(diào)用下面兩個方法切換手機的攝像頭操作)那么就需要使用如下方法:
/*!
@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;