How to get correct PTS for B-Frames when encoding to AVC H.264 videos?

Started by pstein, January 30, 2019, 09:25:29 AM

Previous topic - Next topic

pstein

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

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

@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

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.