第1年6月15日 h264/acc硬编码
1.
https://www.jianshu.com/p/0f0fc1ec311a
-(aw_flv_audio_tag *)encodePCMDataToFlvTag:(NSData *)pcmData{ self.curFramePcmData = pcmData; //构造输出结构体,编码器需要 AudioBufferList outAudioBufferList = {0}; outAudioBufferList.mNumberBuffers = 1; outAudioBufferList.mBuffers[0].mNumberChannels = (uint32_t)self.audioConfig.channelCount; outAudioBufferList.mBuffers[0].mDataByteSize = self.aMaxOutputFrameSize; outAudioBufferList.mBuffers[0].mData = malloc(self.aMaxOutputFrameSize); uint32_t outputDataPacketSize = 1; //执行编码,此处需要传一个回调函数aacEncodeInputDataProc,以同步的方式,在回调中填充pcm数据。 OSStatus status = AudioConverterFillComplexBuffer(_aConverter, aacEncodeInputDataProc, (__bridge void * _Nullable)(self), &outputDataPacketSize, &outAudioBufferList, NULL); if (status == noErr) { //编码成功,获取数据 NSData *rawAAC = [NSData dataWithBytes: outAudioBufferList.mBuffers[0].mData length:outAudioBufferList.mBuffers[0].mDataByteSize]; //时间戳(ms) = 1000 * 每秒采样数 / 采样率; self.manager.timestamp += 1024 * 1000 / self.audioConfig.sampleRate; //获取到aac数据,转成flv audio tag,发送给服务端。 return aw_encoder_create_audio_tag((int8_t *)rawAAC.bytes, rawAAC.length, (uint32_t)self.manager.timestamp, &_faacConfig); }else{ //编码错误 [self onErrorWithCode:AWEncoderErrorCodeAudioEncoderFailed des:@"aac 编码错误"]; } return NULL; } //回调函数,系统指定格式 static OSStatus aacEncodeInputDataProc(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPackets, AudioBufferList *ioData, AudioStreamPacketDescription **outDataPacketDescription, void *inUserData){ AWHWAACEncoder *hwAacEncoder = (__bridge AWHWAACEncoder *)inUserData; //将pcm数据交给编码器 if (hwAacEncoder.curFramePcmData) { ioData->mBuffers[0].mData = (void *)hwAacEncoder.curFramePcmData.bytes; ioData->mBuffers[0].mDataByteSize = (uint32_t)hwAacEncoder.curFramePcmData.length; ioData->mNumberBuffers = 1; ioData->mBuffers[0].mNumberChannels = (uint32_t)hwAacEncoder.audioConfig.channelCount; return noErr; } return -1; }
2.ios利用mic采集Pcm转为AAC,AudioQueue、AudioUnit(流式)
https://www.jianshu.com/p/e2d072b9e4d8
3.
41.FFmpeg学习笔记 - iOS硬编码pcm到aac
https://blog.csdn.net/whoyouare888/article/details/100034182
二、ffplay播放pcm命令
ffplay -f f32le -ac 2 -ar 48000 ./sintel.pcm
其中f32le是pcm格式,2是声道数,48000是采样率。