Skip to content

mpegtsmux: variable PCR offset to avoid overruns

Default PCR offset of 1/8 s is insufficient for most scenarios when a h264 encoder is used with mpeg ts muxer.

In fixed bitrate mode, muxer calculates PCR from number of bytes sent. When encoder has a bitrate spike (e.g when sending a keyframe), number of bits sent exceeds the expected average - this is why PCR offset is needed. When PCR offset is less than (bitrate fluctuation)/bitrate, stream analyzers show "PCR ahead of PTS" error, and presumably decoders suffer and drop frames.

In our experience, depending on encoder bitrate and parameters, and muxer bitrate, this fluctuation typically is closer to 0.25..0.7s than it is to 0.125. It is impossible to predict the best value for all cases, this is why we use variable PCR offset, and default value of 250ms.

Merge request reports