zoukankan      html  css  js  c++  java
  • 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.


  • 相关阅读:
    可视化地图(从省级下钻到市级)
    全国疫情统计可视化地图
    |和||、&&和&
    MFC 常见问题
    * 和-> 优先级
    MFC控件CTabCtrl关联变量
    C++ #include—尖括号和双引号的区别
    C++类型转换
    VC++生成不同的随机数
    VS 2008 头文件库文件设置
  • 原文地址:https://www.cnblogs.com/eustoma/p/2415764.html
Copyright © 2011-2022 走看看