PhilH
PhilH

Reputation: 61

H264 elementary stream format confusion

I've become confused on the format for H264 video streams. Put simply I've read from ISO spec and other sources both that H264 NAL units are delimited by a start code and contain no length information AND that they don't have a start codes and are led by 4 bytes (I know this can vary) giving the length of the NAL unit. To make matters more confusing I've been looking at code in Spydroid and it appears to address both scenarios. Are there two different formats that I'm getting mixed up and if so could anyone direct me to information explaining the two.

Background

To give some background in case it helps I'm working on doing live streaming from Android cameras. The stream will either be split up on device for RTP or sent as the raw MP4 data to be split on a server. Either way the stream will be live so there will be no MOOV info to find the audio and video frames. I believe I have much of the project figured out but I'm basically confused on what it is I should be seeing in the H264 stream. If the length is indeed included in the NAL unit it would definitely help me.

Upvotes: 3

Views: 6480

Answers (2)

PhilH
PhilH

Reputation: 61

According to the following link there are H.264 subtypes. Some have start codes in stream and others have 1, 2 or 4 byte length fields.

http://msdn.microsoft.com/en-us/library/windows/desktop/dd757808(v=vs.85).aspx

So it looks like I will need to do a check for subtype to determine how to parse the stream.

Upvotes: 2

puffadder
puffadder

Reputation: 1824

As far as H.264 bitstream is concerned. it is split up into NAL units, separated by startcode prefix. i.e.

startcode_prefix  NALUnit    startcode_prefix  NALUnit .....  

There is no length information in it because it is a bitstream. You have to look for startcode pattern (0x000001 OR 0x00000001) in the bitstream for the next NAL unit.

More information here: H264 parsing - slice header detection

Upvotes: 3

Related Questions