转载时请注明出处和作者
文章出处:http://www.nanbandao.com/bbs/
作者:Ella
demux和decoder的分离是指将demux出来的数据通过适配层后送给硬件decode,因为HW可以直接解码。
这里记录一下当初遇到的问题。
从av_read_frame出来的码流,一般来讲,已经是比较正规的ES流,通过适配层后送入解码器。所谓适配层是指该平台提供的ES解码所需要的header。
1, mp4/mkv/mov/flv封装的h.264
mp4/mkv/mov/flv,我称之为特殊容器,因为这些容器为了减少存储,减少了一些头信息。
这种容器封装的h.264需要判断ES流中是否包含pps和sps。如果包含,万事大吉,直接送入解码器,如果不包含,则需要进行一些处理。首先是,将sps和pps加入到ES流的前端,然后对av_read_frame出来的ES流进行处理。因为nal单元的起始码是0x000001,此时获得的ES流前4个byte是当前nal的大小,所以将ES数据正规化,然后送入解码器。
2,特殊容器的 AAC;
由于特殊容器的AAC 不是ADTS,因此你需要加入7个bytes的ADTS的头变成ADTS。ADTS header 规范如下:
syncword:12 bits; always: '111111111111'
ID: 1 bits; 0: MPEG-4, 1: MPEG-2
layer: 2 bits ; always: '00'
protection_absent: 1 bits
profile: 2 bits
sampling_frequency_index: 4 bits
private_bit: 1 bits
channel_configuration: 3 bits
original/copy: 1 bits
home: 1 bits
copyright_identification_bit 1 bits
copyright_identification_start 1 bits
aac_frame_length 13 length of the frame including header (in bytes)
adts_buffer_fullness 11 0x7FF indicates VBR
no_raw_data_blocks_in_frame 2 bits
ADTS Error check
crc_check 16 only if protection_absent == 0
After that come (no_raw_data_blocks_in_frame+1) raw_data_blocks.
Some elaborations:
profile
bits ID == 1 (MPEG-2 profile) ID == 0 (MPEG-4 Object type)
00 (0) Main profile AAC MAIN
01 (1) Low Complexity profile (LC) AAC LC
10 (2) Scalable Sample Rate profile (SSR) AAC SSR
11 (3) (reserved) AAC LTP
对于TS,m2ts,mts,由于是标准编码,因此一般由硬件直接demux、decode。
本文探讨了特殊容器如MP4/MKV/MOV/FLV中的H.264编码视频处理方法,包括如何判断并处理ES流中的SPS和PPS信息。同时介绍了AAC音频在特殊容器中的处理方式,涉及ADTS头的构造及其规范。
1049

被折叠的 条评论
为什么被折叠?



