Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture image via captureStillImageAsynchronouslyFromConnection with no shutter sound [duplicate]

I am trying to capture an image during a live preview from the camera, by AVFoundation captureStillImageAsynchronouslyFromConnection. So far the program works as expected. However, how can I mute the shutter sound?

like image 488
ohho Avatar asked Dec 09 '10 17:12

ohho


People also ask

How to remove shutter sound iPhone?

The easiest way to silence the Camera's shutter sound is to put your iPhone in Silent mode. Just flip the Ring/Silent switch – located on the left side of your phone – down, revealing the orange color behind it, and the camera won't make noise when taking a picture.


2 Answers

I used this code once to capture iOS default shutter sound (here is list of sound file names https://github.com/TUNER88/iOSSystemSoundsLibrary):

NSString *path = @"/System/Library/Audio/UISounds/photoShutter.caf"; NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSData *data = [NSData dataWithContentsOfFile:path]; [data writeToFile:[docs stringByAppendingPathComponent:@"photoShutter.caf"] atomically:YES]; 

Then I used third-party app to extract photoShutter.caf from Documents directory (DiskAid for Mac). Next step I opened photoShutter.caf in Audacity audio editor and applied inversion effect, it looks like this on high zoom:

enter image description here

Then I saved this sound as photoShutter2.caf and tried to play this sound right before captureStillImageAsynchronouslyFromConnection:

static SystemSoundID soundID = 0; if (soundID == 0) {     NSString *path = [[NSBundle mainBundle] pathForResource:@"photoShutter2" ofType:@"caf"];     NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];     AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID); } AudioServicesPlaySystemSound(soundID);  [self.stillImageOutput captureStillImageAsynchronouslyFromConnection: ... 

And this really works! I runs test several times, every time I hear no shutter sound :)

You can get already inverted sound, captured on iPhone 5S iOS 7.1.1 from this link: https://www.dropbox.com/s/1echsi6ivbb85bv/photoShutter2.caf

like image 151
k06a Avatar answered Sep 25 '22 07:09

k06a


My Solution in Swift

When you call AVCapturePhotoOutput.capturePhoto method to capture an image like the below code.

photoOutput.capturePhoto(with: self.capturePhotoSettings, delegate: self) 

AVCapturePhotoCaptureDelegate methods will be invoked. And the system tries to play shutter sound after willCapturePhotoFor invoked. So you can dispose of system sound in willCapturePhotoFor method.

enter image description here

extension PhotoCaptureService: AVCapturePhotoCaptureDelegate {      func photoOutput(_ output: AVCapturePhotoOutput, willCapturePhotoFor resolvedSettings: AVCaptureResolvedPhotoSettings) {         // dispose system shutter sound         AudioServicesDisposeSystemSoundID(1108)     } } 

See also

  • AVCapturePhotoDelegate
like image 26
Won Avatar answered Sep 23 '22 07:09

Won