我们正在开发10.7.5及以上的录音应用程序。
我们使用AVCaptureAudioDataOutput
来捕获音频,并使用AVAssetWriterInput
编写数据。
属性设置为AVAssetWriterInput
,如下所示:
AVFormatIDKey:kAudioFormatMPEG4AAC
AVSampleRateKey:此值取自使用以下代码的设备
AudioStreamBasicDescription streanDesc;
UInt32 propSize = sizeof(AudioStreamBasicDescription);
AudioDeviceGetProperty(mInputDevice, 0, YES, kAudioDevicePropertyStreamFormat, &propSize,&streanDesc);
AVNumberOfChannelsKey:这取自AudioStreamBasicDescription。
AVEncoderBitRateKey:硬编码为96000。
除了采样率为32khz的USB麦克风和采样率为48khz的iSight设备外,大多数音频设备都能正常工作。 当我们使用这两个设备作为输入音频设备时,在写入音频数据时我们会收到以下错误 -
Error Domain=AVFoundationErrorDomain Code=-11821 "Cannot Decode" UserInfo=0x279470 {NSLocalizedFailureReason=The media data could not be decoded. It may be damaged., NSUnderlyingError=0x292370 "The operation couldn’t be completed. (OSStatus error 560226676.)", NSLocalizedDescription=Cannot Decode}".
然而,对于USB麦克风,如果我们将AVSampleRateKey
硬编码为44100,它可以很好地工作但不适用于iSight设备。
为AVSampleRateKey
提供的正确值是什么?任何人都可以帮我解决这个问题。