[FFmpeg-devel] [PATCH] libavformat/mpegtsenc: adaptive alignment for teletext PES packets

Marton Balint cus at passwd.hu
Tue Jun 4 20:03:54 EEST 2019

On Tue, 4 Jun 2019, Andreas Håkon wrote:

> Hi Marton,
> Thank you for taking the time to review this patch!
> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
> On Sunday, 2 de June de 2019 1:38, Marton Balint <cus at passwd.hu> wrote:
>> On Wed, 22 May 2019, Andreas Håkon wrote:
>> > Hi,
>> > Patch to generate aligned Teletext PES packets using the MPEG-TS muxer
>> > when the TS header contains data.
>> > The code that generates the PES packets for Teletext data aligns the PES packets
>> > with the boundaries of the TS packets. The strategy used is to insert padding
>> > stuff into the PES header. The size of this padding alignment currently has a
>> > fixed size of 36 bytes. And this value is correct when all of the Teletext
>> > TS packets have payload only. However, inserting some data into the TS header
>> > breaks this assumption. In this case, the Teletext PES packets are not aligned
>> > and the end of the PES packet is inserted into an additional TS packet with a
>> > large amount of TS padding.
>> What is the data that is inserted into the TS header? Can you give an
>> example? Are you sure that it is allowed to generate such streams?
>> Are you seeing such streams in the wild?
> It can vary. For example you can add PCR timestamps inside the Teletext stream
> (not very common, but possible).

The teletext specs also says, that a DVB teletext stream 
adaptation_field_control is either 01 or 10, which means that either there 
is an adaptation field or there is payload. Having both is NOT allowed.

If PCR needs to be transmitted, then it either has to be on a separate PCR 
PID or if you insist on using the same PID then you must use a separate 
packet with adaptation field only if you want to respect the 

>> The DVB teletext spec is very strict about that PES header size and 0x24
>> is hardcoded there.
>> https://www.etsi.org/deliver/etsi_en/300400_300499/300472/01.03.01_60/en_300472v010301p.pdf
> Yes, you're right. The sentence at section "4.2 PES packet format" indicates:
> "PES_header_data_length set to "0x24"." And after it adds:
> "PTS and other optional fields may be present in the PES header,
> but the header length is always fixed for streams
> identified in the Program Specific Information (PSI) by the DVB Teletext descriptor"
> However, the idea of this restriction is to leave space for PTS data even if
> it's not present in the PES packet. And if you don't add any additional stuff
> in the TS header, the constraint is satisfied.
> Perhaps you'd prefer this behavior to be optional?

Our mpegts muxer should not generate streams which are not compliant with 
the relevant specifications. So the proper way to do what you want seems 
to be generating adaptation field only packets.


More information about the ffmpeg-devel mailing list