Author Topic: How to get correct PTS for B-Frames when encoding to AVC H.264 videos?  (Read 149 times)

pstein

  • Jr. Member
  • **
  • Posts: 79
Sometimes when I re-encode MP4 videos with MPEG-4 AVC H.264 codecs I got videos which contain B-Frames with presentation time stamps PTS which are
"either missing or monotonically increasing".

Hmm, what am I doing wrong?

Which AVC H.264 parameter is responsible for the creation of correct presentation time stamps for B-frames?

Currently I am using the following parameters:

Number of B-Frames= 3
B-Frame mode= auto
Adaptive B-Frame=Optimal
B-Pyramid=None
Weighted B-Prediction=yes
B-Frame bias=0

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 2527
Re: How to get correct PTS for B-Frames when encoding to AVC H.264 videos?
« Reply #1 on: January 30, 2019, 06:19:34 PM »
If you save to a container supporting frame reordering (i.e. MKV or MP4, not AVI), this absolutely should not happen, unless there is a bug in libx264. Could you please provide a sample source video with a project script necessary to reproduce this issue? Which Avidemux version do you refer to? Can you reproduce it with the latest nightly?

pstein

  • Jr. Member
  • **
  • Posts: 79
Re: How to get correct PTS for B-Frames when encoding to AVC H.264 videos?
« Reply #2 on: February 02, 2019, 01:09:03 PM »
@eumagga0x2a:

Thank you.

So that means if I save it in AVI container it could happen (depending on which parameter?) or will always happen?

eumagga0x2a

  • Moderator
  • Hero Member
  • *****
  • Posts: 2527
Re: How to get correct PTS for B-Frames when encoding to AVC H.264 videos?
« Reply #3 on: February 02, 2019, 02:51:32 PM »
This will always happen if B-frames are enabled (the number of B-frames is not equal zero) in x264 or x265 encoder settings (which means that the display order is different from the stream order).

By the way, you must ignore a warning when trying to save a H.264 or HEVC stream to AVI container. This warning is there not just for good looks, albeit it doesn't take details like a possibility that B-frames may be disabled / not present into account.

If you get prompted for PTS missing when loading an AVI with H.264 or HEVC video stream you have generated, you are at fault and everything works as expected.