Configure MPEG-TS Packet Size in FFmpeg
This article explains how to configure packet sizes within the FFmpeg MPEG-TS (MPEG Transport Stream) muxer. It covers the native configuration of standard 188-byte packets, the 192-byte M2TS mode, and the technical workarounds required to achieve 204-byte packets with Reed-Solomon (RS) error coding, which is not natively supported by FFmpeg’s default muxer.
Understanding MPEG-TS Packet Sizes
MPEG-TS packets traditionally exist in three sizes depending on the transmission medium and error-correction requirements:
- 188 Bytes: The standard MPEG-TS packet size used in most broadcasting and streaming environments.
- 192 Bytes: Used in Blu-ray disc systems (M2TS), which prepends a 4-byte Time Stamp to the standard 188-byte packet.
- 204 Bytes: Used in DVB transmission systems, which appends 16 bytes of Reed-Solomon (RS) forward error correction data to the 188-byte packet.
Configuring 188-Byte Packets (Default)
By default, FFmpeg’s mpegts muxer outputs standard
188-byte packets. No additional flags are required to enforce this
packet size.
ffmpeg -i input.mp4 -c copy -f mpegts output.tsConfiguring 192-Byte Packets (M2TS Mode)
To output 192-byte packets, you must enable the M2TS mode flag. This adds a 4-byte TP_extra_header to each 188-byte transport stream packet.
ffmpeg -i input.mp4 -c copy -f mpegts -mpegts_m2ts_mode 1 output.m2tsHandling the 204-Byte Reed-Solomon (RS) Requirement
Standard FFmpeg does not contain a native encoder to calculate and
append the 16-byte Reed-Solomon (204, 188) error correction code to
create true 204-byte packets directly from the mpegts
muxer.
In broadcasting workflows, this conversion is typically handled at the hardware layer (such as by a DVB modulator, ASI output card, or IP gateway) rather than in the software multiplexer.
However, if you require a 204-byte format for software compatibility, you must use a post-processing tool.
Workaround: Using TSDuck for 204-Byte Conversion
The open-source MPEG Transport Stream toolkit TSDuck can convert a standard 188-byte FFmpeg output into a 204-byte format by appending dummy or calculated RS bytes.
Generate the standard 188-byte stream in FFmpeg:
ffmpeg -i input.mp4 -c:v libx264 -c:a aac -f mpegts - | tsp -O file output_204.tsConvert the packet format using TSDuck (
tscatortsp): You can pipe FFmpeg’s output directly into TSDuck to pad the packets to 204 bytes:ffmpeg -i input.mp4 -f mpegts - | tsp -I input-file -O file --format 204 output_204.ts
Using this workflow ensures compliance with systems requiring strict 204-byte packet alignments.