I'm trying to write some code in C that will demux a MPEG2 transport stream into elementary streams. I'm using ffmpeg to compare the output that I'm generating from my code. The output stream from my program is basically bit-exact with ffmpeg except for one case. ffmpeg seems to be picking up the byte 0xff from the bitstream when it is at the start of the payload (after the end of the PES header and PES stuffing bytes), while I'm excluding it as a PES stuffing byte.
My question is this: Is the length of the stuffing byte(0xff) in the PES packet variable or is it encoded in the PES header as well?
note: The way I'm reading the payload data from the PES packet is I basically skip all the initial 0xff until I hit a byte that is not 0xff and read till the end of the packet from there