Re: MPEG2-transport stream
A transport packet consist of 188-bytes and always start with the $47 sync byte. Like you indicate, the payload in that packet can also contain such a sync byte, so you do have to be aware of that.
If you capture a TS stream then they already contain the sync bytes and such, so you don't have to add anything to the data (except when the capture device provides 184 bytes, which the software of some DVB cards seem to do).
Depending on how the capture is done, the data is already sync based (thus the first data is the sync byte). When the data is not synchronized then it is relatively easy to get it synchronized, because the $47 sync byte occurs every 188 bytes. You basically discard all bytes until you find a $47. Then you check again after 188 bytes. If no $47, restart (discarding until next $47).
Header information and such can be found in ISO/IEC 13818-1 and related documents.
I suggest you have a look here, although these might not be the latest documents):
**broken link removed**
Note: Since I am not a regular visitor of this forum, when have additional questions for me, then go to
www.majority.nl and use the email address there to respond ...