Many structures of FFmpeg have avrational time_base; Such a member, it is the avrational structure of the
typedef struct avrational{
int num; < numerator
int den; < denominator
} avrational;
Avrational This structure identifies a fraction, num is the fraction, and den is the denominator.
In fact time_base means the timescale of time:
such as (1,25), then the timescale is 1/25
(1,9000), then the timescale is 1/90000.
Then, the time=5 in the system with scale 1/25 is converted to the time of the scale 1/90000 system (5*1/25)/(1/90000) = 3600*5=18000
There is a large number of such conversions in FFmpeg when doing PTS calculations
In the following structure, there are
Avcodeccontext: Codec context.
Avstream: A track in a file or other container.
If a fixed frame rate stream is generated by a decoder
The avrational in the Avcodeccontext is set according to the frame rate, such as 25 frames, then num = 1,den=25
Time_base in Avstream are generally set according to their sampling frequency, e.g. (1,90000)
In some scenarios involving the calculation of PTS, it involves the conversion of two time, and exactly where the time_base is taken:
Scenario 1: The frame generated by the encoder is deposited directly into the avstream of a container, then the time of packet is converted from Avcodeccontext to the target avstream.
Scenario 2: A frame of source Avstream demux out of a container, stored in another container for a purpose avstream.
The timescale at this time should be converted from the time of the source avstream to the times under the destination Avstream timebase.
In fact, the key to the problem is to understand, the different scenarios to take the data frame of time is relative to which system.
Demux out of frame time: is relative to the source Avstream timebase
The encoder comes out of the frame time: is relative to the source Avcodeccontext timebase
The time of a mux to a container such as a file: a timebase relative to the purpose Avstream
Time here refers to Pts.
Thorough analysis of ffmpeg structure--avrational