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

AVCaptureSession audio doesn’t work for long videos

Edit (because this answer is still getting upvotes): This answer works to mitigate the problem but the likely root cause for the issue is addressed in @jfeldman’s answer. I found the solution as an answer to a completely different question. The issue is the movieFragmentInterval property in AVCaptureMovieFileOutput. The documentation for this property explains what … Read more

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

AVCaptureSession and background audio iOS 7

In your AppDelegate: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Stop app pausing other sound. [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDuckOthers | AVAudioSessionCategoryOptionDefaultToSpeaker error:nil]; } Where you are allocating AVCaptureSession: AVCaptureSession *session = [[AVCaptureSession alloc] init]; session.automaticallyConfiguresApplicationAudioSession = NO; This code will allow you to play background music and run AVCaptureSession with the microphone. SWIFT UPDATE: AppDelegate: func … 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

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

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