NSError *error = nil; session = [[AVCaptureSession alloc] init] ; session.sessionPreset = AVCaptureSessionPresetMedium; AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];//这里默认是使用后置摄像头,你可以改成前置摄像头 AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; if (!input) { } [session addInput:input]; AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init]; [session addOutput:output]; dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL); [output setSampleBufferDelegate:self queue:queue]; output.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey, [NSNumber numberWithInt: 320], (id)kCVPixelBufferWidthKey, [NSNumber numberWithInt: 240], (id)kCVPixelBufferHeightKey, nil]; AVCaptureVideoPreviewLayer* preLayer = [AVCaptureVideoPreviewLayer layerWithSession: session]; preLayer.frame = self.view.bounds; preLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.view.layer addSublayer:preLayer]; output.minFrameDuration = CMTimeMake(1, 15); [session startRunning];