How do I use the metadataOutputRectOfInterestForRect method and rectOfInterest property to scan a specific area? (QR Code)

I wasn’t really able to clarify the issue with metadataOutputRectOfInterestForRect, however, you can directly set the property as well. You need to the have the resolution in width and height of your video, which you can specify in advance. I quickly used the 640*480 setting. As stated in the documentation, these values have to be … Read more

Trying to understand CMTime

A CMTime struct represents a length of time that is stored as rational number (see CMTime Reference). CMTime has a value and a timescale field, and represents the time value/timescale seconds . CMTimeMake is a function that returns a CMTime structure, for example: CMTime t1 = CMTimeMake(1, 10); // 1/10 second = 0.1 second CMTime … Read more

Avoiding blurriness at start & end of video (even after using setPreferredVideoStabilizationMode:AVCaptureVideoStabilizationModeAuto)?

Video is blurry by its nature. 24 or 30 frames per second video will always have some blur in the shot because that’s the way our eyes are tricked into believing the pictures are actually moving. The longer shutter speed allows the camera to give the impression of motion. Photos use a much shorter shutter … Read more

Barcode on swift 4

I figured it out but Apple didn’t make it so obvious. The callback function from the delegate AVCaptureMetadataOutputObjectsDelegate has been renamed and the parameter names are different! So, replace func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!) to func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) My view controller is now … Read more

Switch cameras with avcapturesession

You first need to remove the existing AVCameraInput from the AVCaptureSession and then add a new AVCameraInput to the AVCaptureSession. The following works for me (under ARC): -(IBAction)switchCameraTapped:(id)sender { //Change camera source if(_captureSession) { //Indicate that some changes will be made to the session [_captureSession beginConfiguration]; //Remove existing input AVCaptureInput* currentCameraInput = [_captureSession.inputs objectAtIndex:0]; [_captureSession … Read more

How to apply “filters” to AVCaptureVideoPreviewLayer

Probably the most performant way of handling this would be to use OpenGL ES for filtering and display of these video frames. You won’t be able to do much with an AVCaptureVideoPreviewLayer directly, aside from adjusting its opacity when overlaid with another view or layer. I have a sample application here where I grab frames … Read more

Turn on torch/flash on iPhone

Here’s a shorter version you can now use to turn the light on or off: AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if ([device hasTorch]) { [device lockForConfiguration:nil]; [device setTorchMode:AVCaptureTorchModeOn]; // use AVCaptureTorchModeOff to turn off [device unlockForConfiguration]; } UPDATE: (March 2015) With iOS 6.0 and later, you can control the brightness or level of the torch … Read more