Reading information from the PAT section (MPEG-TS)
I am writing a parser for MPEG-TS files and I am stuck with getting program_values ββand PIDs from PAT section. I am using a packet analyzer to compare my results.
For example, here is the PAT package
47 40 00 16 00 00 B0 31 00 14 D7 00 00 00 00 E0
10 00 01 E0 24 00 02 E0 25 00 03 E0 30 00 04 E0
31 00 1A E0 67 00 1C E0 6F 43 9D E3 F1 43 A3 E3
F7 43 AC E4 00 C3 69 A6 D8 FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF
FF FF FF FF FF FF FF FF FF FF FF FF
I first started comparing the parser results against bytes to see the connection. He concatenated bytes like this: [00 10] [01 24] [02 25] [03 30] etc. I noticed a pattern (for i = 14; i <end; i + = 4) but that quickly turned wrong because after the "0x6F" byte it started reading 16 bits, not 8, so the program_number was 0x439D.
I'm seriously confused and hope someone can explain to me how to parse the PAT example from above.
source to share
Each program_number
is 16 bits followed by 16 bits consisting of 3 x '1' bits and 13 bits program_map_pid
(or network_pid if
program_number` = 0)
Start at offset 13 in the dump and read pairs of 16-bit words, masking the top 3 bits of the second word.
eg.
offset bytes words program_number pid
====== =========== ========= ============== ======================
000D: 00 00 E0 10 => 0000 E010 => 0000 0010 (network_pid)
0011: 00 01 E0 24 => 0001 E024 => 0001 0024 (program_map_pid)
0015: 00 02 E0 25 => 0002 E025 => 0002 0025 (program_map_pid)
0019: etc..
001D: etc..
0021: etc..
0025: 00 1C E0 6F => 001C E06F => 001C 006F (program_map_pid)
0029: 43 9D E3 F1 => 439D E3F1 => 439D 03F1 (program_map_pid)
002D: etc..
etc..
In theory, this is more difficult, since there can be several program association sections in PAT, and the above will only help with the 1st section.
For details, see section 2.4.4.3 of ISO / IEC 13818-1, in particular Table 2-25.
source to share
Considering the PAT dump above, 47 is the sync byte, the 13-bit pid is retrieved from bytes 40 00, and the adaptation field control is retrieved from byte 16 (01) i, that is, only the payload.
So the payload follows immediately after the 4 byte header, the fifth byte 00 should have been the table I would be from PAT.
But according to the dump table I will be the sixth byte which is 00.
Can someone please explain what is the fifth byte 00 in the dump?
source to share