[Live-devel] H264VideoFramer truncating frames

Ross Finlayson finlayson at live555.com
Mon Mar 30 13:30:01 PDT 2015


> Then I do not see how you can make a "generic" parser without
> knowing in advance whether the start code is 3 or 4 bytes.

No, it’s actually quite easy.  If you know that the start code is either 0x00 0x00 0x01 or 0x00 0x00 0x00 0x01, then the following code (taken from our H.264/5 stream parser, used in “H264or5VideoStreamFramer”) does the trick:

      while (next4Bytes != 0x00000001 && (next4Bytes&0xFFFFFF00) != 0x00000100) {
        // We save at least some of "next4Bytes".                                                  
        if ((unsigned)(next4Bytes&0xFF) > 1) {
          // Common case: 0x00000001 or 0x000001 definitely doesn't begin anywhere in "next4Bytes", so we save all of it:                                                                            
          save4Bytes(next4Bytes);
          skipBytes(4);
        } else {
          // Save the first byte, and continue testing the rest:                                   
          saveByte(next4Bytes>>24);
          skipBytes(1);
        }
        setParseState(); // ensures forward progress                                               
        next4Bytes = test4Bytes();
      }
     // Assert: next4Bytes starts with 0x00000001 or 0x000001, and we've saved all previous bytes (forming a complete NAL unit).                                                                    
      // Skip over these remaining bytes, up until the start of the next NAL unit:                 
      if (next4Bytes == 0x00000001) {
        skipBytes(4);
      } else {
        skipBytes(3);
      }
   }

Ross Finlayson
Live Networks, Inc.
http://www.live555.com/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20150330/f2540420/attachment.html>


More information about the live-devel mailing list