Set PMT and PCR PIDs in FFmpeg MPEG-TS Muxer

Configuring specific Packet Identifiers (PIDs) for the Program Map Table (PMT) and Program Clock Reference (PCR) is crucial for compatibility with professional broadcast hardware and multiplexers. This article provides a straightforward guide on how to set the PMT PID and control the PCR PID using FFmpeg’s MPEG-TS muxer options, complete with practical command-line examples.

Setting the PMT PID

By default, FFmpeg assigns a default PID to the Program Map Table (PMT). You can explicitly set the PMT PID using the -mpegts_pmt_start_pid private muxer option. FFmpeg accepts values in both decimal and hexadecimal formats.

To set the PMT PID to 4096 (which is 0x1000 in hex), use the following option in your command:

-mpegts_pmt_start_pid 0x1000

Setting the PCR PID

In an MPEG-TS container, the PCR (Program Clock Reference) is not a standalone stream; instead, it is embedded within the adaptation field of an existing elementary stream (usually the primary video stream).

To set or change the PCR PID, you must assign a specific PID to the stream that carries the PCR. In FFmpeg, this is achieved using the -streamid option, which maps an output stream index to a custom PID.

The syntax is:

-streamid output_stream_index:new_pid

For example, if your video stream is the first output stream (index 0) and you want its PID (and consequently the PCR PID) to be 256 (0x100 in hex), you would use:

-streamid 0:256

Complete Command Example

Below is a complete FFmpeg command that muxes an input file into an MPEG-TS stream, setting the PMT PID to 0x1000 (4096), the Video/PCR PID to 0x100 (256), and the Audio PID to 0x101 (257):

ffmpeg -i input.mp4 \
  -c:v copy -c:a copy \
  -f mpegts \
  -mpegts_pmt_start_pid 0x1000 \
  -streamid 0:256 \
  -streamid 1:257 \
  output.ts

Verification

To verify that the PIDs were set correctly, you can analyze the output file using ffprobe:

ffprobe -show_streams -show_programs output.ts