简体   繁体   English

音频 (`AVAssetWriterInput` & `AVAudioRecorder`) 优化设置

[英]Audio (`AVAssetWriterInput` & `AVAudioRecorder`) Optimal settings

I'm currently building an app with video and audio recording (foreground and background).我目前正在构建一个带有视频和音频录制(前景和背景)的应用程序。

There are some reports from my clients that some of the recordings are failing, now I've checked with their logs and it seems that on some devices the encodings settings are not good.我的客户有一些报告说某些录音失败,现在我检查了他们的日志,似乎在某些设备上编码设置不好。 I have search all over the web to find a decent source of information on how should I config the recording objects AVAssetWriterInput & AVAudioRecorder .我在 web 中进行了搜索,以找到有关如何配置录制对象AVAssetWriterInputAVAudioRecorder的体面信息来源。 Currently this is my settings for both of the objects目前这是我对这两个对象的设置

        let recorderSettings: [String: Any] = [
            AVFormatIDKey: kAudioFormatMPEG4AAC,
            AVNumberOfChannelsKey: 2,
            AVSampleRateKey: 44100,
            AVEncoderBitRateKey: 64000,
            AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue
        ]

Any help would be appreciated, thanks任何帮助将不胜感激,谢谢

BTW this is the error I'm getting顺便说一句,这是我得到的错误

"AssetWrtiting finished with 
Optional(Error Domain=AVFoundationErrorDomain Code=-11861
"Cannot Encode Media" 
UserInfo={NSLocalizedFailureReason=The encoding parameters are not supported.
NSLocalizedDescription=Cannot Encode Media,
NSUnderlyingError=0x2839b7750 {Error Domain=NSOSStatusErrorDomain Code=-12651 "(null)"}})

Just a FYI, if you are stumbling upon this question.仅供参考,如果您偶然发现这个问题。

The outputs of the AVCaptureSession AVCaptureVideoDataOutput & AVCaptureAudioDataOutput has a method to get the recommended settings for recording called AVCaptureSession AVCaptureVideoDataOutputAVCaptureAudioDataOutput的输出有一个方法来获取录制的推荐设置,称为

func recommendedAudioSettingsForAssetWriter(writingTo outputFileType: AVFileType) -> [AnyHashable : Any]?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM