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];