A timestamp consists of a time reference and a timestamp value.
Time benchmark: the criteria for dividing the time unit (s.
For example, 1/25 indicates 25 units per second. Each unit interval contains 1 unit.
3001/90000 indicates that each second is divided into 90000 units, and each unit interval contains 3001 units.
Timestamp value: the time representation based on the time reference, that is, the number of unit time intervals.
1) The timestamp is used to accurately mark the relative position and duration of audio and video streams.
2) using a timestamp based on the time benchmark, rather than using an integer, means that the timestamp can avoid division failures.
3) There is an error in timestamp conversion between different time benchmarks. Unnecessary conversions should be avoided.
If conversion is required, ensure that the timestamp after conversion is not earlier than before conversion.
4) Compare the direct timestamps of different time benchmarks, which should be first converted to a more detailed unit (1/1hns.
5) The system clock is equivalent to 1/1000 of the timestamp. The audio and video playback synchronization is actually a comparison between the stream's own Timestamp and the system timestamp.
As there is an error in time stamp conversion, there is also an error in playback synchronization. Therefore, do not tangle with equal signs, but try to set a tolerable error duration.
Timestamp conversion in FFMPEG
Avformatcontext-> avpacket-> avframe-> avpacket-> avformatcontext
Avstream avcodeccontext avstream
Decoding process: Because avstream and avcodeccontext are created in the file parsing process, the time_base of the two should be consistent.
The timestamp value from avpacket to avframe remains unchanged.
Encoding Process: The time_base of avcodeccontext is set by the user (the default value is 1/90000), and The time_base in avstream is the default value 1/90000 (the value of FFMPEG in write_header is modified to match avcodeccontext). The values are not necessarily equal, therefore, time stamp value conversion is required.