Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>here is my code, it works perfect for me , you can refer to it </p> <pre><code>- (void)initCapture { AVCaptureDevice *inputDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:inputDevice error:nil]; if (!captureInput) { return; } AVCaptureVideoDataOutput *captureOutput = [[AVCaptureVideoDataOutput alloc] init]; /* captureOutput:didOutputSampleBuffer:fromConnection delegate method !*/ [captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]; NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key]; [captureOutput setVideoSettings:videoSettings]; self.captureSession = [[AVCaptureSession alloc] init]; NSString* preset = 0; if (!preset) { preset = AVCaptureSessionPresetMedium; } self.captureSession.sessionPreset = preset; if ([self.captureSession canAddInput:captureInput]) { [self.captureSession addInput:captureInput]; } if ([self.captureSession canAddOutput:captureOutput]) { [self.captureSession addOutput:captureOutput]; } //handle prevLayer if (!self.captureVideoPreviewLayer) { self.captureVideoPreviewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession]; } //if you want to adjust the previewlayer frame, here! self.captureVideoPreviewLayer.frame = self.view.bounds; self.captureVideoPreviewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill; [self.view.layer addSublayer: self.captureVideoPreviewLayer]; [self.captureSession startRunning]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload