What is PTS in reference to video encoding?
PTS, which stands for Presentation Time Stamp, is commonly translated as '展示时间戳' in Chinese. It is used to indicate the exact time at which video frames or audio frames should be displayed on the playback device. PTS is a critical component in video encoding as it ensures synchronization and smooth playback of video.During video encoding and decoding, the original video content is compressed into frames, which may be reordered due to the requirements of the compression algorithm. For example, to improve compression efficiency, the encoder may use B-frames (bidirectional predictive frames), which require reference to frames before and after them for encoding. This means that the order of frames may be altered during encoding.PTS is used to solve this problem. It marks the time at which each frame should be displayed, regardless of their actual order in the bitstream. At the decoder end, the decoder reads the PTS of each frame and uses this timestamp to correctly arrange the display order of frames, ensuring that the video content is presented without temporal errors.For example, consider a video sequence with the original frame order I1, P1, B1, B2, P2 (where I-frames are key frames, P-frames are forward predictive frames, and B-frames are bidirectional predictive frames). During encoding, the storage order of frames may become I1, P1, P2, B1, B2 to more efficiently compress the data. Each frame is assigned a PTS to ensure that during decoding, even if the storage order is altered, the playback order follows the original sequence I1, P1, B1, B2, P2, maintaining the correct presentation of the video.Therefore, PTS plays a crucial role in maintaining the accuracy and smoothness of video playback.