pythonmpeg

Using Python to extract the first 188-byte packet from MPEG Transport Stream but do not see the sync byte


I have the following code in Python:

with open("my_transport_stream_file.ts", "rb") as f:
    data = f.read(188)
    print(data)

In my mind, I believe I am extracting the first 188 bytes from the file i.e the first transport stream packet. Here's what I get:

b'G@\x00\x10\x00\x00\xb0\r\x00\x01\xc1\x00\x00\x00\n\xe0e\x8d,\xa3\xec\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff'

Whilst this is SUPER exciting because I can see some data, I don't see the 0x47 sync byte that I am expecting to see.

What am I missing?


Solution

  • I can see it there, It’s the very first byte.

    0x47 is the ASCII code for capital letter G.

    Whatever you are using to print that string, prints ASCII characters as is, but converts non printable values (values less than 0x20 and greater than 0x7e) to hex, or another escape code, like \r is 0x0d and \n is 0x0a

    http://www.asciitable.com/