Skip to content

mfvideoenc: Enhance B-frame timestamp handling

When B-frame is enabled, encoder seems to adjust PTS of encoded sample by using frame duration.

For instance, one observed timestamp pattern by using B-frame enabled and 30fps stream is:

  • Frame-1: MF pts 0:00.033333300 MF dts 0:00.000000000
  • Frame-2: MF pts 0:00.133333300 MF dts 0:00.033333300
  • Frame-3: MF pts 0:00.066666600 MF dts 0:00.066666600
  • Frame-4: MF pts 0:00.099999900 MF dts 0:00.100000000

We can notice that the amount of PTS shift is frame duration and Frame-4 exhibits PTS < DTS.

To compensate shifted timestamp, we should calculate the timestamp offset and re-calculate DTS correspondingly. Otherwise, total timeline of output stream will be shifted, and that can cause time sync issue.

Merge request reports