• H264和MPEG4起始码(startcode)


    http://blog.chinaunix.net/space.php?uid=20751538&do=blog&id=165746

    1. H.264起始码
      在网络传输h264数据时,一个UDP包就是一个NALU,解码器可以很方便的检测出NAL分界和解码。但是如果编码数据存储为一个文件,原来的解码器将无法从数据流中分别出每个NAL的起始位置和终止位置,为此h.264用起始码来解决这一问题。
     
      H.264编码时,在每个NAL前添加起始码 0x000001,解码器在码流中检测到起始码,当前NAL结束。为了防止NAL内部出现0x000001的数据,h.264又提出'防止竞争 emulation prevention"机制,在编码完一个NAL时,如果检测出有连续两个0x00字节,就在后面插入一个0x03。当解码器在NAL内部检测到0x000003的数据,就把0x03抛弃,恢复原始数据。
       0x000000  >>>>>>  0x00000300
       0x000001  >>>>>>  0x00000301
       0x000002  >>>>>>  0x00000302
       0x000003  >>>>>>  0x00000303
     
     附上h.264解码nalu中检测起始码的算法流程 
     for(;;)
     {
        if next 24 bits are 0x000001
        {
            startCodeFound = true
            break;
        }
        else
        {
            flush 8 bits 
        }
     }// for(;;)

     if(true == startCodeFound)
     {
         //startcode found
         // Flush the start code found
         flush 24 bits 
         //Now navigate up to next start code and put the in between stuff
         // in the nal structure.
         for(;;)
         {
             get next 24 bits & check if it equals to 0x000001
             if(false == (next 24 bits == 000001))
             {
                 // search for pattern 0x000000
                 check if next 24 bits are 0x000000
                 if(false == result)
                 {
                     // copy the byte into the buffer
                     copy one byte to the Nal unit              
                 }
                 else
                 {
                     break;
                 }
              }
              else
              {
                  break;
              }
           }//for(;;)
       }
      2. MPEG4起始码
            MPEG4的特色是VOP,没有NALU的概念,仍使用startcode对每帧进行分界。MPEG4的起始码是0x000001. 另外MPEG4中很多起始码也很有用,比如video_object_sequence_start_code 0x000001B0 表示一个视频对象序列的开始,VO_start_code 0x000001B6 表示一个VOP的开始. 0x000001B6之后的两位,是00表示 I frame, 01 表示 P frame, 10 表示 B frame.


  • 相关阅读:
    【BZOJ2434】[NOI2011]阿狸的打字机 AC自动机+DFS序+树状数组
    【BZOJ1030】[JSOI2007]文本生成器 AC自动机+动态规划
    【BZOJ3943】[Usaco2015 Feb]SuperBull 最大生成树
    【BZOJ3940】【BZOJ3942】[Usaco2015 Feb]Censoring AC自动机/KMP/hash+栈
    【BZOJ3172】[Tjoi2013]单词 AC自动机
    【HDU2896】病毒侵袭 AC自动机
    【HDU2222】Keywords Search AC自动机
    【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP
    结婚晚了
    无毒食品
  • 原文地址:https://www.cnblogs.com/eustoma/p/2415764.html
Copyright © 2020-2023  润新知