Log in

View Full Version : h.264 nal unit


chia0176
26th December 2010, 08:57
Hi,

I would like to identify h.264 files from a list of random file types. The start code prefix of h.264 NAL unit is 0x000001. However 0x000001 also occurs in other file types eg. jpeg. Hence, i am not able to just search for 0x000001 to confirm that it is a h.264 file. Is there any other pattern unique to h.264 file type?

i would also like to ask how do i determine h.264 NAL unit length field? Say NAL unit starts when we see the start code prefix 0x000001. How much more bytes after 0x000001 will be the end of a NAL unit?

Thank you very much. I have done lots of researching in these 2 areas but am still stuck. Kindly help me.

imcold
26th December 2010, 09:19
There isn't any unique pattern in h.264 streams. The NAL unit end is marked by the start code prefix of next NAL unit (or EOF); the start code prefix is forbidden within NAL unit.

chia0176
26th December 2010, 09:26
Thank you imcold.

Am i right to say that there is no way to find the NAL unit length field (eg. length of NAL unit is 4 bytes)? We can only know the NAL unit length upon spotting the next 0x000001?

imcold
26th December 2010, 19:16
Not sure I understand you, but NAL doesn't have length field. If the bytestream is wrapped in some container, then the container may contain some information about NALs, possibly even their length. Answer to second question is yes, you'll just have to search through the stream. You may take a look at h264bitstream (https://sourceforge.net/projects/h264bitstream/), it has code for h.264 stream parsing.

shjuspea
29th December 2010, 10:15
As I understand, what you really need is probing each file by pre-fetching numbers of data (not only according to the file extension):

1. Identify which file format a file is using according to corresponding spec of container (e.g. TS, MP4, AVI);
2. Retrieved desired info (e.g. a/v codec) either from meta data of container (e.g. moov box/atom in MP4, CodecID of VideoTagHeader in FLV) or parsing using some pattern as you mentioned.

Enjoy!

Selur
29th December 2010, 10:21
btw. couldn't one simply use mediainfo for the whole thing?

roozhou
29th December 2010, 16:45
btw. couldn't one simply use mediainfo for the whole thing?
MediaInfo does not provide interface to parse NALs, though it has internal functions doing such things. One can look at MediaInfo's h264 parser and write his/her own.

Selur
30th December 2010, 16:25
I mainly ment MediaInfo as a response to "I would like to identify h.264 files from a list of random file types." and thought about calling:
mediainfo --Inform=Video;%Format% "Path to file" for each file and if the output of the call is AVC it's a h.264 file. :P