美文网首页
AVCaptureSession

AVCaptureSession

作者: lltree | 来源:发表于2017-12-13 17:44 被阅读55次

    参考
    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;
    

    相关文章

      网友评论

          本文标题:AVCaptureSession

          本文链接:https://www.haomeiwen.com/subject/uscaixtx.html