FFmpeg's understanding about Timebase

Source: Internet
Author: User

FFmpeg's understanding about Timebase


One: FFmpeg's layered structure

When writing this article, let's outline the FFmpeg layering problem, which we summarize in accordance with the most common "transcoding program" and "Camera capture" and "player" three models.

1: transcoding

transcoding basic Flow: FLV Format Data-->H264/AAC data-->YUV/PCM data-->H264/AAC data-->mp4 format data.

A: We call the FLV format data or the MP4 format data This layer is called the MUX/DEMUX layer or the multiplex layer some people are accustomed to be called the encapsulation layer, here is called the MUX/DEMUX layer below the same.

B: We call this layer of H264/AAC data a codec layer or codec/decode, which is called the Codec/decode layer.

C: We call this layer of the YUV/PCM data layer or raw data layer, which is referred to as the raw database layer.

2: Camera Capture

Camera Capture Basic process: YUV/PCM data-->H264/AAC Data-->flv format data.

A: We call this layer of the YUV/PCM data layer or raw data layer, which is referred to as the raw database layer.

B: We call this layer of H264/AAC data a codec layer or codec, which is called the codec layer.

C: We take the FLV format Data layer called the MUX layer or the multiplexing layer some people are accustomed to called the encapsulation layer, this is called the MUX layer under the same.

3: Player

Basic player process: FLV format Data-->H264/AAC data-->YUV/PCM data.

A: We take the FLV format Data layer called the DEMUX layer or the multiplex layer some people are accustomed to called the encapsulation layer, here is called the DEMUX layer below the same.

B: We call this layer of H264/AAC data a codec layer or decode, which is called the decode layer.

C: We call this layer of the YUV/PCM data layer or raw data layer, which is referred to as the raw database layer.


From the above three most commonly used models are not difficult to see can also be summed up ffmpeg basically the data or the structure of the "Mux/demux layer" that is ffmpeg avstream

The "Codec/decode layer" is the Avcodec "Raw data Layer" in FFmpeg, which is also avstream stored in (if it is self-filled for example iOS or Android gets the current millisecond time can be placed separately into a TIMEBSE structure), this. Crossing you have a general understanding of this stratification, we say the effect of stratification on timebase.


II: What is the timebase in FFmpeg

1: To put it simply, FFmpeg's timebase is a mechanism for converting to integers when a stamp is fractional and for a better hierarchical structure.

2:ffmpeg Timebse We can understand as units, such as meters, milliseconds, seconds, kilograms these are units, but this timebse is sometimes not the unit we can see in daily life, for example FFmpeg itself is based on the second, 1 seconds = 1000 milliseconds, that if Timebse is 1:1 very good understanding is the unit of the second, if Timebase is 1:1000 also very good understanding is the millisecond unit, but if Timebase is 1:25, our common unit can not explain, this if a lot of people's misunderstanding.


Three: The relationship between hierarchical structure and timebase in FFmpeg

1: timebase example of a few commonly used FFmpeg

A:mux/demux layer of Timebase,flv,mp4 and so on is generally 1:1000,ts is generally 1:90*1000.



The B:codec/decode layer timebase,h264 with frame rate variations such as 1:25 AAC based on sample rate variations such as 1:44,100.



There are many changes in the timebase of the C:raw data layer, such as 1:1000*1000 or 1:1000.


This screenshot is ffmpeg on the Windows platform of the camera capture timebase, if it is iOS or Android can get the system in milliseconds time to set Timebase to 1:1000, the same.


2:ffmpeg on the transformation process of layered structure timebase

A: transcoding model

First, the timebase of the DEMUX layer is obtained by the hierarchical structure, and the FLV data, the timebase of the Demux layer, is converted to codec of the timebase layer.

picture->pts = Av_rescale_q_rnd (Picture->pts,streams->time_base,streams->decodectext->time_base, Av_round_near_inf);

Then the timebase of the decode layer is converted into codec layer (the two same layers but also need to convert) Timebase, here is a problem Raw data layer timebase can be skipped, can be directly from decode to Coedec,raw data The timebse of the layer is used in the camera capture and player.

picture->pts = Av_rescale_q_rnd (picture->pts,streams->decodectext->time_base,streams->codectext- >time_base, Av_round_near_inf);
Finally, the timebase of the codec layer is converted to the timebase of the MUX layer.

picture->pts = Av_rescale_q_rnd (picture->pts,streams->codectext->time_base,streams->time_base,av_ Round_near_inf);
B: Collection model

First get to the raw data layer timebase If Windows can be read from streams Timebase, iOS and Android can write their own timebase structure for conversion, Converts the acquired timebase to the timebase of the codec layer.

picture->pts = Av_rescale_q_rnd (Picture->pts,timebase_in,streams->codectext->time_base, AV_ROUND_NEAR _inf);
The timebase of the codec layer is then converted to the timebase of the MUX layer

picture->pts = Av_rescale_q_rnd (Picture->pts,streams->codectext->time_base, streams->timebase,AV_ Round_near_inf);
C: Player model

First, the timebase of the DEMUX layer is converted to the timebase of the decode layer.

picture->pts = Av_rescale_q_rnd (Picture->pts,streams->time_base,streams->decodectext->time_base, Av_round_near_inf);
The timebase of the decode layer is then converted to the Raw data layer of the player timebase typically set to 1:1000 in order to convert the timestamp to milliseconds.

picture->pts = Av_rescale_q_rnd (picture->pts,streams->decodectext->time_base,1:1000, AV_ROUND_NEAR_ INF);

The relationship between the FFmpeg stratification and the timebase of the three models is explained clearly, and if there is a problem there is a need to communicate and learn from one another.

The output screenshot of FFmpeg is as follows:



If there is an error, please correct me:
Exchange Please add QQ Group: 62054820
qq:379969650.

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.