.wav to any compressed form from AVAssetWritter ios

南笙酒味 提交于 2019-12-03 03:59:20

ANSWER

This is the correct audio options for .m4a and if you want the user to see it as an .mp3 or .wav file just append those onto the end of the file name!

AudioChannelLayout channelLayout;
memset(&channelLayout, 0, sizeof(AudioChannelLayout));
channelLayout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                            [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
                            [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                            [NSNumber numberWithInt:2], AVNumberOfChannelsKey,
                            [NSNumber numberWithInt:128000], AVEncoderBitRateKey,
                            [NSData dataWithBytes:&channelLayout    length:sizeof(AudioChannelLayout)], AVChannelLayoutKey,                  

                            nil];    

How about this (sorry for not trying it myself but it should get you closer):

AVAssetWriter *assetWriter = [AVAssetWriter assetWriterWithURL:exportURL
                                                       fileType:AVFileTypeAppleM4A
                                                          error:&assetError];

NSDictionary *outputSettings = [NSDictionary dictionaryWithObjectsAndKeys:
       [NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
       [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
       [NSNumber numberWithInt:2], AVNumberOfChannelsKey,
       [NSNumber numberWithInt:128000], AVEncoderBitRateKey,
       [NSNumber numberWithInt:16], AVLinearPCMBitDepthKey,
       [NSNumber numberWithInt: AVAudioQualityHigh],  AVEncoderAudioQualityKey,
       nil];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!