iOS camera 相关

来源:互联网 发布:步鑫生失败原因 知乎 编辑:程序博客网 时间:2024/06/06 01:53
1、设置帧率和旋转

    AVCaptureVideoDataOutput *videoOut = [[AVCaptureVideoDataOutput alloc] init];

    [videoOut setAlwaysDiscardsLateVideoFrames:NO];

    [videoOut setVideoSettings:[NSDictionary dictionaryWithObject:

                                [NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange]//kCVPixelFormatType_420YpCbCr8BiPlanarFullRange

                                                           forKey:(id)kCVPixelBufferPixelFormatTypeKey]];

    [videoOut setSampleBufferDelegate:self queue:_captureVideoDispatchQueue];

    AVCaptureConnection *videoConnection = [_videoOut connectionWithMediaType:AVMediaTypeVideo]    

    if ([videoConnection isVideoMinFrameDurationSupported]) {//帧率

        videoConnection.videoMinFrameDuration = CMTimeMake(1, 15);

    }

    if([_videoConnection isVideoOrientationSupported])//旋转

        _videoConnection.videoOrientation = AVCaptureVideoOrientationPortrait;


2、设置预览模式为平铺

    AVCaptureVideoPreviewLayer* previewLayer = [AVCaptureVideoPreviewLayer layerWithSession: _captureSession];

    previewLayer.frame = view.bounds;

    previewLayer.videoGravity = AVLayerVideoGravityResize;

    [view.layer addSublayer: previewLayer];

    _previewLayer = previewLayer;


3、录制正方形

    NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:

                                   AVVideoCodecH264, AVVideoCodecKey,

                                   codecSettings,AVVideoCompressionPropertiesKey,

                                   [NSNumber 240], AVVideoWidthKey,

                                   [NSNumber 240], AVVideoHeightKey,

                                   nil];

    

    videoWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];

0 0
原创粉丝点击