[Audio and video processing] Why is MP3 not lossless music? Detailed explanation of audio parameters, the relationship between bit rate, sampling rate, audio frame, bit depth, channel, and encoding format

Hi everyone, and welcome to the Stop Refactoring channel.

In the previous issue, we discussed the related concepts of video. In this issue, we discussed the related concepts of audio .

Including sampling rate, bit rate, single and dual channels, audio frame, encoding format and other concepts .

Here is a question about lossless audio.

Why is .mp3 with 48KHz sampling rate not lossless music, but .wav and .flac audio with 48KHz sampling rate are lossless?

We classify and discuss audio-related concepts in this order:

1. The concept of audio sampling

2. The concept of a single audio frame

3. The concept of multiple audio frames

The concept of audio sampling

Related concepts are: sampling, bit depth, channel, sampling rate .

Unlike video, the smallest unit of audio is not a frame, but a sample .

A sample is a sound sample of the sound at the current moment , and the sample needs to be digitally converted before it can be stored as sample data.

During digital conversion, it will be converted according to the bit depth . The bit depth is the size of storing a single sample data . The larger the bit depth, the higher the accuracy of the recorded sample data.

The general bit depth of network video and audio files is 16bit , and commonly used bit depths are 8bit, 24bit, etc.

What needs to be mentioned here is that the larger the bit depth means the higher the degree of sound reproduction, but too high bit depth , such as 32bit, 64bit float or above, may require special software and hardware equipment to play.

接下来是声道,音频有单声道、双声道、立体声等。

每个声道的声音样本都会单独记录,一般双声道的采样数是单声道的两倍,多声道同理。

多个声道的样本数据一般会按声道排列顺序记录,播放时,程序会根据排列顺序将声音用不同的扬声器播放。

采样率是采样的频率,与视频的帧率类似,是一秒钟对声音的采样个数,如果是双声道,那么1秒采样的个数是采样率的两倍,多声道同理。

普遍认为,流畅且不失真的音频,要求采样率达到40KHz以上,这个采样率是人类听觉频率上限的两倍,一般CD品质音频的采样率是44.1KHz,网络视频、视频文件一般是48KHz。

不过,某些具体场景可能会降低采样率要求,如语音通话、监控摄像头等,这些场景下,音频采样率一般只有8KHz,这个频率虽然听音乐是一种折磨,会一卡一卡的,但是对听清别人说话倒是一点问题没有。

单个音频帧的概念

这里我们理解为什么存在音频帧就可以了。

理论上,音频并不需要音频帧的概念,因为音频采样数据和采样率已经可以把音频播放描述清楚了。

但是音视频文件播放时,为了保证音视频同步,程序需要根据每帧的播放时间戳进行有序播放。

但是每个音频采样数据太小了,如果每个采样数据都记录播放时间戳的话,那么就得不偿失了。毕竟一个时间戳数据的大小比一个音频采样数据都大,所以就有了音频帧的概念。

音频帧实际上就是把一小段时间的音频采样数据打包起来,如每20ms的音频采样数据合并成一帧。

这里的具体时间间隔是具体编码码格式决定的,一般不需要特别关心。

多个音频帧的概念

多个音频帧的概念有播放时间戳PTS、码率、编码格式。与

视频帧一样,每一帧音频帧也会记录播放时间戳PTS,程序播放时会根据播放时间戳PTS播放音频帧。

音频帧的播放是比较特别的,因为一帧音频包含的是一小段时间的音频采样,所以实际上音频帧的播放时间戳只是这一小段音频的开始播放时间里面的采样数据会根据采样频率连续播放

同时音频也有码率,也就是常听到的音频比特率,码率就是一秒钟的数据量大小

不压缩的情况下,音频码率的大小=采样率*位深度声*道数。

接下来是编码格式,编码格式实际上是压缩数据的方式,常用的编码格式有wav、mp3、aac等,音频编码格式有有损、无损压缩之分

这里可以解释开篇的问题了,为什么采样参数相同的mp3和wav文件会有不同的音质,这实际上是编码格式的问题。

mp3、aac这些编码格式是有损压缩,其中mp3支持的最大码率是320Kbps,而wav编码格式是无损压缩,虽然压缩后的码率可能会比降低,但是它在播放时能无损还原采样数据。

最后值得一提的是,在网络音频文件、音频直播时,需要考虑限制码率,限制码率的目的是为了限制数据量的大小,避免带宽、流量等问题。

音频编码格式一般采用aac,音频码率一般设置为128Kbps就可以了。

总结

以上是音频的基础概念,音频在很多介绍中都不会说到音频帧,因为普通的视频编辑场景是用不到的,但是在音视频处理中音频帧的概念是十分重要的,不然会出现很多问题,如音频重编码重采样后,出现卡顿、音频播放过快等问题。

介绍完了音频和视频的基础概念,后面我们会介绍关于音视频处理、识别的一些软件和框架。

Guess you like

Origin blog.csdn.net/Daniel_Leung/article/details/129114601