Skip to content

Instantly share code, notes, and snippets.

@happyj2me
Last active September 2, 2021 08:09
Show Gist options
  • Save happyj2me/232ba14a036c38ed024780933b5726c2 to your computer and use it in GitHub Desktop.
Save happyj2me/232ba14a036c38ed024780933b5726c2 to your computer and use it in GitHub Desktop.
17(1-key,7-avc) 00(avc sps/pps) 00 00 00(composition time) 01(version) 64 00 1F FF
E1(sps-num) ------ 偏移10的这个字节 & 0x1f == sps-num
00 19(sps len)
xx xx xx xx xx xx(sps)
01(pps-num)
00 04(pps len)
xx xx xx xx(pps)
17(1-key,7-avc) 01(avc nalu) 00 00 28(composition time)
00 00 00 02(nalu-len) 09(nalu pkg, 09&0x1f=9,访问单元分隔符) 30
00 00 23 74(nalu-len) 65(nalu pkg, 65&0x1f=5,IFram) xx xx xx xx xx
27(2-inter frame,7-avc) 01(avc nalu) 00 00 50(composition time)
00 00 00 02(nalu-len) 09(nalu pkg, 09&0x1f=9,访问单元分隔符) 50
00 00 35 1f(nalu-len) 61(nalu pkg, 61&0x1f=1,inter frame) xx xx xx xx xx
对视频来说,我们要做的就是从rtmp包里面提取出来sps/pps或者nalu pkg,再加上起始码0x00 00 00 01发送给webrtc打包成RTP包
以AAC LC 为例,其他格式有变动
AACDecoderSpecific(2 bytes) + AACSpecificConfig(2 bytes) ---- 出现一次,说明音频的编码信息,否则无法解码(音频同步包)
AACDecoderSpecific(2 bytes) + Raw(aac data)        ---- 出现多次(音频数据)
我们要做的就是从rtmp音频里面提取出来AACSpecificConfig信息,根据它创建7字节的ADTS头,把ADTS + Raw(aac data)部分数据交给AAC解码器处理,
解码并重采样以后,再把得到的PCM数据交给webrtc的音频采集部分
AACDecoderSpecific(1 or 2 bytes):
audioFormatType(4 bits) : 0(pcm,platform endian),2(mp3),3(pcm,little endian),7(G.711 A-law),8(G.711 mu-law), 10(AAC), 11(Speex)
audioSampleType(2 bits) : 0(5.5kHz),1(11kHz),2(22kHz),3(44kHz)
audioSampleLen(1 bits) : 0(8 bits),1(16 bits)
audioChannelType(1 bits) : 0(mono),1(stereo)
aacpacketType(8 bits) : 0x00(后面是音频同步包AACSpecificConfig),0x01(后面是音频数据) --- 这个字段只有audioFormatType == 10才存在
AACSpecificConfig(2 bytes):
AudioObjectType (5 bits): 1(AAC Main),2(AAC LC),3(AAC SSR),4(AAC LTP) .... 45(USAC)
SampleRateIndex (4 bits): 0(96000),1(88200),2(64000),3(48000),4(44100),5(32000),6(24000),7(22050),8(16000),9(12000),10(11025),11(8000),12(7350)
ChannelConfig (4 bits): 1(front center),2(front-left,front-right)...... 6(6 channels),8(8 channels)
FrameLengthFlag (1 bits): IMDCT窗口长度(默认为0)
dependOnCoreCoder (1 bits): (默认为0)
extensionFlag (1 bits): (默认为0)
ADTS(audio data transport stream): 7 bytes, 前面两字节一般固定为FFF9
syncword (12 bits): 0xFFF
ID (1 bits): 0(MPEG-4),1(MPEG-2) ----AAC 默认为1
layer (2 bits): 00
protection_absent (1 btis): 0           ----AAC 默认为1
profile (2 bits): 0(AAC Main),1(AAC LC),2(AAC SSR),3(reserved)
sampling_frequency_index(4 bits): 同AACSpecificConfig里面的SamleRateIndex
private_bit (1 bits): 0
channel_configuration (3 bits): 同AACSpecificConfig里面的ChannelConfig
original_copy (1 bits): 0
home (1 bits): 0
copyright_identification_bit(1 bits): 0
copyright_identification_start(1 bits):0
aac_frame_length(13 bits): ADTS(7 bytes) + Raw(aac data)
adts_buffer_fullness(11 bits): 0x7ff
number_of_raw_data_blocks_in_frame(2 bits): 00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment