Thorough analysis of ffmpeg structure--avrational

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.