Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i parse H264 file and frames

An H264 file is a stream of NAL (Network Abstraction Layer) units, each encoding a frame (I, B, or P). What is the best way to parse this file and to extract sizes and detect ends of each NAL unit in the file, as well as detect the type of frame the NAL unit contains?

like image 274
Harry Avatar asked Apr 12 '12 12:04

Harry


1 Answers

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

Here's what you need to know:

  • NAL Units start code: 00 00 01 X Y
  • X = IDR Picture NAL Units (e.g 25, 45, 65)
  • Y = Non IDR Picture NAL Units (e.g. 01, 21, 41, 61)

So, if you find 3 bytes [00 00 01] in sequence, very likely it's the beginning of the NAL unit. Then you will need to parse the the next two bytes [X Y] to find out the type of frame. Please refer to the spec for more details.

like image 187
George Skoptsov Avatar answered Oct 17 '22 09:10

George Skoptsov