Configure PAT and PMT Intervals in FFmpeg MPEG-TS
This article explains how to configure the Program Association Table (PAT) and Program Map Table (PMT) transmission intervals in an MPEG Transport Stream (MPEG-TS) using FFmpeg. You will learn about the specific command-line parameters required to adjust these intervals, allowing you to optimize stream join times, reduce overhead, and comply with strict broadcasting standards.
In an MPEG-TS container, the PAT and PMT are essential tables that a media player must read to identify and decode the audio and video streams. By default, FFmpeg writes these tables into the stream at fixed intervals. However, you can manually control this frequency using the MPEG-TS muxer private options.
The
-pat_period_frames Option
FFmpeg controls the PAT and PMT insert interval based on the number
of video frames using the -pat_period_frames option.
The default value is 100, meaning FFmpeg inserts a PAT and PMT packet every 100 frames.
To change this interval, use the following syntax:
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f mpegts -pat_period_frames 50 output.tsIn this example, the PAT/PMT tables will be sent every 50 frames.
Calculating the Time Interval
Because FFmpeg sets the interval in frames rather than milliseconds, you must calculate the value based on your video’s frame rate (fps) to achieve a specific time-based interval.
\[\text{pat\_period\_frames} = \text{Target Interval (seconds)} \times \text{Frame Rate (fps)}\]
Example Configurations:
For a 100ms (0.1s) interval at 30 fps: \[0.1 \times 30 = 3 \text{ frames}\]
ffmpeg -i input.mp4 -c copy -f mpegts -pat_period_frames 3 output.tsFor a 500ms (0.5s) interval at 25 fps: \[0.5 \times 25 = 12.5 \approx 13 \text{ frames}\]
ffmpeg -i input.mp4 -c copy -f mpegts -pat_period_frames 13 output.ts
Configuring SDT Intervals
Along with the PAT and PMT, the Service Description Table (SDT) is
also sent periodically. You can adjust its interval using the
-sdt_period_frames option in the same manner:
ffmpeg -i input.mp4 -c copy -f mpegts -pat_period_frames 12 -sdt_period_frames 12 output.tsWhy Adjust These Settings?
- Faster Tuning Times: Lowering the
pat_period_framesvalue (e.g., to send tables every 100ms to 250ms) allows hardware receivers and players to discover the stream structure faster, reducing black-screen time when a user switches channels. - Bandwidth Optimization: If you are streaming over a bandwidth-constrained network, increasing the frame interval reduces the packet overhead caused by repeating these tables too frequently.