How can I parse an H264 file and frames

An H264 file is a stream of Network Abstraction Layer (NAL) blocks, each of which encodes a frame (I, B, or P). What is the best way to parse this file and retrieve the sizes and determine the ends of each NAL unit in the file, and also determine the type of frame that contains the NAL unit?

+6
source share
2 answers

You can use Media Foundation if your Vista platform is higher: http://msdn.microsoft.com/en-us/library/windows/desktop/dd797815%28v=vs.85%29.aspx there are application examples in the SDK

-3
source

If you're not really trying to decode frames, you can write a simple "parser" by reading the h.264 byte stream and looking for a NAL signature.

Here is what you need to know:

  • NAL Trigger Code: 00 00 01 XY
  • X = NRRR image units (e.g. 25, 45, 65)
  • Y = UnIDR Picture NAL Units (e.g. 01, 21, 41, 61)

So, if you find 3 bytes [00 00 01] in a sequence, it is very likely that this is the beginning of a NAL block. Then you will need to parse the next two bytes [XY] to find out the type of frame. See spec for more details.

+20
source

Source: https://habr.com/ru/post/913031/


All Articles