Log in

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


mike23
30th January 2019, 10:15
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

videoh
30th January 2019, 15:51
It's the muxer that creates the timestamps, not the encoder.

nevcairiel
30th January 2019, 16:18
If you use x264 for encoding (through the API), it'll give you proper re-ordered PTS timestamps which you can just pass to the muxer for straight up writing. I would assume that most H.264 encoders can produce timestamps, since they perform the re-ordering of the frames anyway.
Similarly, if you use x264 CLI, it'll also generate the timestamps and have its internal muxers write them into a file. Unless you write a raw .h264 file anyway, since that doesn't have timstamps.

Many muxers are capable of parsing the H.264 bitstream and re-creating the timestamps if they are missing, though. But I wouldn't put that onto a muxer as primary task.

If you have an existing encode that has wrong timestamps, you could try various muxers and see which can repair it for you. I'm not sure from the top of my head. If you are encoding those videos yourself and get that problem, there might be an issue with your workflow that loses/corrupts timestamps somewhere.