Python programming practice: Detailed explanation of how to use Python to parse key information such as PAT, PMT, PCR, PTS, DTS in MPEG-TS

Introduction

MPEG-TS (MPEG Transport Stream) is a standard for transmitting video and audio. It is a core component of digital television and other high-definition streaming services. MPEG-TS contains multiple types of tables, including PAT (Program Association Table), PMT (Program Map Table), and other timestamp information such as PCR (Program Clock Reference), PTS (Presentation Time Stamp), and DTS (Decoding Time Stamp).

This article will introduce how to use Python to write a simple program to parse MPEG-TS and extract the above key information. We will use the basic functionality of Python without any external libraries.

Basic knowledge of parsing MPEG-TS

Before we begin, we need to understand the basic structure of MPEG-TS.

  1. Packet: MPEG-TS stream is composed of a series of fixed-length packets, each packet is usually 188 bytes in length.
  2. PID (Packet Identifier): Each packet has a PID, which is used to identify the contents of the packet.
  3. Tables: MPEG-TS contains a variety of tables, the most important of which are PAT and PMT. These tables contain stream metadata.

Now let's analyze these tables in detail.

1. Parse PAT

PAT (Program Association Table) is the core part of MPEG-TS, which provides a mapping between a program number and its associated PID.

Here is a Python function for parsing PAT:

 

Guess you like

Origin blog.csdn.net/qq_38334677/article/details/133002737