This simple Python module provides fucntions for parsing MPEG2 TS
into TS packets and extracting video and audio streams by their PIDs. It also allows to view the transport stream packet by packet in a summarized form.
Just import the package and use parse_TS()
function to parse the TS packets from a file.
import ts_parser as tsp
TS_packets = tsp.parse_TS('data/sample.ts')
Then, the audio and video streams can be directly extracted using extract_stream()
tsp.extract_stream(TS_packets, 257, 'data/PID257.mp2') # audio
tsp.extract_stream(TS_packets, 256, 'data/PID256.264') # video
The module also offers a function for assembling PES
packets of specific PID
.
PES_packets = tsp.reassemble_PES(TS_packets, 257)
This is a simple module. It does not parse all the packet fields (at least yet), especially those not requiered to extract audio or video from the transport stream.