I have been working on video transcoding recently for my organization’s video processing pipeline and for transcoding purposes I have been using FFmpeg. Most of our videos are user-generated content and for some of them while transcoding I am receiving the following error/warning message from FFmpeg: Application provided invalid, non-monotonically increasing dts to muxer in the stream.
What does this message mean and how can I avoid it?
To understand this warning, we need to understand what are DTS and PTS values first. When a player or a software tries to decode and play the video, both audio and video streams have information about how fast and when you are supposed to play them inside of them. Audio streams have a sample rate, and video streams have a frame-per-second value. However, if we simply synced the video by just counting frames and multiplying by frame rate, there is a chance that it will go out of sync with the audio.
Decoding time stamps (DTS) and presentation time stamps (PTS) are two possible features of packets from the stream.
H.264 (AVC) and H.265 (HEVC) like codecs store a video in three kinds of frames: ’ I ’ frame, ‘ P ’ frame, and ‘ B ’ frame.
• I: frames contain a full image.
• P: frames depend upon previous I and P frames and are like diffs or deltas.
• B: frames are the same as P frames but depend upon information found in frames that are displayed both before and after them.
When B-frames are not used with transcoding, PTS and DTS are the same but the problem arises when B-frames are used. Usually, the decoded frame contains PTS and DTS information inside the packet but we need PTS of our newly decoded raw frame, so we know when to display it.
This warning is thrown when FFmpeg finds the decode sequence timestamps associated with samples or frames are not increasing monotonically. Usually, FFmpeg takes care of these kinds of issues on its own.
With the help of FFmpeg, you can also re-generate PTS for a video using -fflags genpts but usually, it does not solve the issue in my experience.
If your video plays fine then you should not worry about these kinds of warnings.