"mpegts_demux" is a tool that reads a TS file and dump the video/audio streams into disk.
For each stream a file named audio_id_xxx
or video_id_xxx
is generated with the raw stream data.
The dumped data can be viewed by ffmpeg.
Make like build
make
mpegts_demux [-i] input_file.ts
Default invokation will only read PES packets that contain audio/video streams and dump them to disk.
While the -i
switch will read the program information to identify all programs and their associated streams.
mpegts_demux elephants.ts
Read program information
mpegts_demux -i elephants.ts
List of files:
- MpegTs.hpp: Definitions of structs and special numbers
- MpegTsBitStream.hpp/.cpp: Class for reading TS bit stream.
- MpegTsDemux.hpp/.cpp: Class for parsing and demuxing, contain definitions for streams.
- mpegts_demux.cpp: main function for the program.
The code base is organized into 2 modules:
- Bit stream reader.
This handles reading bit stream from input file and converting it into packets of fixed 188 bytes. 188 bytes is only supported for now. Source files for this module in
MpegTsBitStream.cpp
andinclude/MpegTsBitStream.hpp
. MethodMpegTsBitStream::GetPacket()
handles reading bitstream and packing it into TS packetsPacket
. - TS packet reader and demuxer.
This module operates on fixed size packets - which make running out of data easier to check and handle.
MpegTsDemuxer::DecodePacket()
is the entry point for handling new packets. Firstly, packet header is parsed to get the packet identifierPID
. The demuxer uses the concept of filters/actions; for eachPID
of interest, its checked against a list of know identifiers of interest saved inMpegTsDemuxer::m_filters
. When the command line switch "-i" is set, the PAT/PMT identifies thePID
of streams, which in turn will be registered in the filters to pick them up. In the absence of the program data - no "-i" switch or packets that appears before PAT/PMT, theMpegTsDemuxer::CheckPES
method tries to probe the packet if it is a PES packet and if so, the packet will be parsed. one thing to note here is that changes/updates to stream program number is allowed, and a warning messege will be issued for that. Finally, with stream registered, aStream
class object is instantiated which hold aFILE*
to the output file to dump the stream into.