FFMPEG的应用之demux 和decoder的分离

来源:互联网 发布:mysql在线数据库设计 编辑:程序博客网 时间:2024/04/30 15:53

转载时请注明出处和作者
文章出处: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。

原创粉丝点击