Log in

View Full Version : MPEG PES -> AVI or elementary stream.. how does the padding work?


blueshift
17th December 2007, 20:03
I am trying to use MPEG-4 ASP video produced by a hardware encoder chip that gives me PES packets. If I remove the 32-byte PES header (00 00 01 E0 start code) the data looks a lot like a reference file I have, but I note that there are a variable number of zero bytes at the end of each PES packet, e.g. 26 bytes on one packet I'm looking at.

The video plays back in VLC but glitches, either as raw concatenated packets minus the 32-byte header, or multiplexed into an AVI. I am trying to work out if the zeroes at the end of the packets are a problem.

I have looked at ISO/IEC 13818-1 and -2 documents but can't find a length value at a lower level than the PES header, which includes the trailing zeros. The docs are pretty heavy going though and I may have missed something.

A reference MPEG4 in AVI file that I have has no trailing zeros at the end of its packets, another thing that makes me wonder if I'm doing it wrong.

Could anyone point me to a spec, or tell me if the trailing zeroes are allowed, or how to calculate the correct length of valid data I should be using..

Thanks! this is a real headache.

Guest
17th December 2007, 20:27
Taking the ES out of a PES is not as simple as just removing the start code. You have to fully parse the PES packet because there is a lot of overhead there that can vary in size and whose presence is signalled with flags. Your guide of course should be Table 2-17 in the MPEG2 Systems spec. You can look at open source code that does this kind of parsing, e.g., DGMPGDec.

You need to get rid of everything except the PES packet data bytes.

BTW, padding at the end of a PES packet is 0xff, and not 0x00.