1, Outline This period of time to do transcoding, calculate pts when the time is converted to a base, I think this pts if there is no original PTS do reference how to calculate its value. Groping for a while to understand the clue recorded here.
2. Video pts Video is better understood, that is, each frame increments, if FPS is 25 frames, the time base is the countdown of FPS 1/25, then the PTS increment can be. As follows: First frame: Pts=0 second frame: Pts=1 third frame: pts=3 ... Nth Frame: pts = n-1;
。。。 And so on, the formula is: the nth frame of pts = n * ((1/timbase)/fps);
3, audio pts Audio is relatively more difficult to understand some, because the audio of a packet more than one frame, so how many packet a second does not know, don't say how to calculate pts. Assuming that the audio has NUM_PKT packet a second, what is this num_pkt? From the beginning of the audio base, we know that the audio has a sampling rate, that is, how many times a second, a lot of audio is 44100 sampling rate, also has 8k, then this sample rate and num_pkt have what relationship. We found that there is a more important field in Avframe called Nb_samples, this field is named Sample number, this field can be combined with the audio data format to calculate how large this frame->data, In fact, this field combined sample rate can also calculate how many packet the audio has in a second. The calculation formula is as follows: NUM_PKT = sample rate/nb_samples; So we know the number of packets per second of audio (which can be seen as frames), and with this data the PTS are exactly the same as the video, and the formula is as follows: The PTS of the nth packet = n * ((1/timbase)/NUM_PKT); A lot of the audio time base and the sampling rate are reciprocal, then according to the formula our audio pts can be very simple to nb_samples increment, as follows: The first packet: pts = 0 * nb_samples; Second Package: pts = 1 * nb_samples;
Third Package: pts = 2 * nb_samples;
. . . Nth Package: pts = (n-1) * nb_samples;
Note: The above-mentioned timebase is the timebase in Avstream.
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.