I'm working on an iOS project which uses AVAssetWriter and AVAssetWriterInput to record audio and video to file. Everything seemed to work fine when the video resolution was limited to 720x1280. I'm now trying to take advantage of the AVCaptureDeviceFormats for higher resolutions available on newer iOS devices.
The video continues to work fine using any of the AVCaptureDeviceFormats available on the device. However, the audio does not work.
I've tracked this down to the active
property of my audio AVCaptureConnection, which is NO
for the highest-resolution formats, looking like this when I log it:
<AVCaptureConnection: 0x16f62130 [type:soun][enabled:1][active:0]>
Also, my didOutputSampleBuffer
delegate callback is not called with audio data when the audio connection is not active.
My questions:
- why is the audio AVCaptureConnection active for lower resolution formats, but not for the highest resolution formats?
- is it possible to record audio when the video resolution is set to the highest? If so, how?
Example:
The highest-resolution AVCaptureFormats on an iPhone6, back camera:
- 720x1280, 30 FPS (audio connection active)
- 720x1280, 240 FPS (audio connection active)
- 1080x1920, 30 FPS (audio connection active)
- 1080x1920, 60 FPS (audio connection active)
- 1936x2592, 30 FPS (audio connection not active)
- 2448x3264, 30 FPS (audio connection not active)
The highest-resolution AVCaptureFormats on an iPhone6, front camera:
- 720x1280, 60 FPS (audio connection active)
- 960x1280, 60 FPS (audio connection not active)
Here's the code I'm using to set the active format:
if ([self.camera lockForConfiguration:nil])
{
self.camera.activeFormat = format;
[self.camera unlockForConfiguration];
}
来源:https://stackoverflow.com/questions/29241365/why-is-my-audio-avcaptureconnection-not-active-for-highest-resolution-formats