Ios 使用AVCaptureSession全屏捕获视频
我需要我的应用程序显示前摄像头正在拍摄的内容的实时预览,并且该视频流的尺寸需要与设备的屏幕大小相匹配 但在预览视图的顶部和底部会出现黑色条。。。 如何捕获和预览具有全屏尺寸的视频?注意,我不想调整视频的大小 下面是我的代码:Ios 使用AVCaptureSession全屏捕获视频,ios,iphone,avfoundation,Ios,Iphone,Avfoundation,我需要我的应用程序显示前摄像头正在拍摄的内容的实时预览,并且该视频流的尺寸需要与设备的屏幕大小相匹配 但在预览视图的顶部和底部会出现黑色条。。。 如何捕获和预览具有全屏尺寸的视频?注意,我不想调整视频的大小 下面是我的代码: session = [[AVCaptureSession alloc] init]; session.sessionPreset = AVCaptureSessionPresetPhoto; AVCaptureDevice *device = [AVCaptureDev
session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetPhoto;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
[session addInput:input];
UIView *cameraPreviewView = [[UIView alloc] initWithFrame:self.view.frame] ;
[self.view addSubview:cameraPreviewView];
AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];
[session addOutput:output];
dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);
[output setSampleBufferDelegate:self queue:queue];
AVCaptureVideoPreviewLayer *cameraPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
cameraPreviewLayer.frame = cameraPreviewView.bounds;
[cameraPreviewView.layer addSublayer:cameraPreviewLayer];
[cameraPreviewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
[cameraPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
[session startRunning];
尝试“NSLOG”cameraPreviewLayer和UIView的框架;我认为这就是罪魁祸首:cameraPreviewLayer.frame=cameraPreviewView.bounds…