Av_rescale_q is used to calculate the PTS for packet. The return value of Av_rescale_q is a large integer, and the result interval for each calculation is very large. Unlike Avcodec_encode_video, the PTS (Small integer and small interval) that changed Avcodeccontext *avctx.
Av_rescale_q (a,b,c) is a function used to adjust the timestamp from one time base to another. Its basic action is to calculate the a*b/c, but this function is still necessary, because the direct calculation will have overflow situation occurs. Av_time_base_q is the version of Av_time_base as the denominator. They are very different: av_time_base * time_in_seconds = Avcodec_timestamp and av_time_base_q * Avcodec_timestamp = time_in_seconds (Note av_ Time_base_q is actually a Avrational object, so you must use the specific Q function in Avcodec to handle it.
h264/90000, the representative clock frequency must be 90000
Background knowledge:
(An AAC original frame contains 1024 samples and related data over a period of time)
1. Video time stamp
PTS = inc++ * (1000/fps); Where Inc is a static, initial value of 0, each time the timestamp Inc plus 1.
In FFmpeg, the code in
pkt.pts= m_nvideotimestamp++ * (M_vctx->time_base.num * 1000/m_vctx->time_base.den);
2. Audio time stamp
PTS = inc++ * (frame_size * 1000/sample_rate)
The code in FFmpeg is
pkt.pts= m_naudiotimestamp++ * (m_actx->frame_size * 1000/m_actx->sample_rate);
The sampling frequency is the number of times per second that the acoustic amplitude sample is sampled when the analog sound waveform is digitized.
。 The frequency range of normal hearing is approximately between 20hz~20khz, according to the Nyquist sampling theory, in order to ensure that the sound is not distorted, the sampling frequency should be around 40kHz. Commonly used audio sampling frequency 8kHz, 11.025kHz, 22.05kHz, 16kHz, 37.8kHz, 44.1kHz, 48kHz, etc., if the use of higher sampling frequency, but also to achieve the sound quality of the DVD
When decoding AAC audio with a sampling rate of 44.1kHz, the decoding time of a frame must be controlled within 23.22 milliseconds.
Background knowledge:
(An AAC original frame contains 1024 samples and related data over a period of time)
Analysis:
1 AAC
Playback time of the audio frame = number of samples/sample frequency (in s) for the corresponding sample of an AAC frame
A frame of 1024 sample. Sample Rate Samplerate 44100Hz, 44,100 samples per second, so the playback time of the audio frame according to the formula = the number/sampling frequency of the sample sample corresponding to an AAC frame
The playback time of the current AAC frame is = 1024*1000/44100= 22.32ms (in ms)
2 MP3
MP3 Each frame is 1152 bytes, then:
frame_duration = 1152 * 1000/sample_rate
For example: Sample_rate = 44100HZ, the calculated length is 26.122ms, this is often heard mp3 each frame playback time fixed to 26ms.
The frame rate of the video will change.