Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用AVCaptureSession全屏捕获视频_Ios_Iphone_Avfoundation - Fatal编程技术网

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…