音视频基础知识

常见的音频编码器

常见的音频编码器包括OPUS(速度快,压缩率大),AAC(最为广泛的),Ogg,Speex,iLBC,AMR,G.711其中,ACC在直播系统中应用的比较广泛,OPUS是较新的音频编解码,WebRTC模式使用OPUS,固话一般使用G.711(损耗很大)系列。评测结果:OPUS>AAC>Ogg。

音频编码质量比较

音频编码率比较

 ACC

AAC(Advanced Audio Coding)由许多知名公司开发,其目的是取代MP3格式,其最开始是基于MPEG-2的音频编码技术,MPEG-4标准出现以后,AAC重新集成了其特性,加入了SBR和PS技术。常见的规格有AAC LC、AAC HE V1和AAC HE V2。

  • AAC LC : (Low Complexity)低复杂度规格,码流是128k ,音质好。
  • AACHE :等于AAC LC + SBR (Spectral Band Replication)。其核心思相是按频谱分保存。低频编码保存主要成分,高频单独放大编码保存音质。码流在64k左右。
  • AAC HE V2 :等于AACLC + SBR + PS(Parametric Stereo)。其核心思相是双声道中的声音存在某种相似性,只需存储一个声道的全部信息,然后,花很少的字节用参数描述另一个声道和它不同的地方。

AAC格式

  • ADIF ( Audio Data Interchange Format ),这种格式的特征是可以确定的找到这个音频数据的开始,只能从头开始解码,不能在音频数据流中间开始。这种格式常用在磁盘文件中。
  • ADTS ( Audio Data Transport Stream ),这种格式的特征是每一帧都有一个同步字,所以可以在音频流的任何位置开始解码。它类似于数据流格式。

ADTS的结构

ADTS由7/9个字节组成

12syncword OxFFF, all bits must be 1
1MPEG Version; 0 for MPEG- -4, 1 for MPEG -2
2Layer: always 0
1protection absent, Warning, set to 1 if there is no CRC and 0 if there is CRC
2profle, the MPEG- -4 Audio Object Type minus 1
4MPEG-4 Sampling Frequency Index (15 is forbidden)
1private bit, guaranteed never to be used by MPEG, set to 0 when encoding, ignore when decoding
3MPEG- .4 Channel Configuration (in the case of 0, the channel configuration is sent via an inband PCE)
1originality, set to O when encoding, ignore when decoding
1home, set to 0 when encoding, ignore when decoding
1copyrighted id bit, the next bit of a centrally registered copyright identifier, set to 0 when encoding, ignore when decoding
1copyright id start, signals that this frame's copyright id bit is the first bit of the copyright id, set to 0 when encoding, ignore when decoding
13frame length, this value must include 7 or 9 bytes of header length: FrameLength = (ProtectionAbsent == 1? 7: 9) + size(AACFrame)
11Buffer fullness
2Number of AAC frames (RDBs) in ADTS frame minus 1, for maximum compatibility always use 1 AAC frame per ADTS frame
16CRC if protection absent is 0

Audio Object Types

  • 1: AAC Main
  • 2:AACLC
  • 5: SBR
  • 29: PS

Sampling Frequency Index

  • 0: 96000 Hz
  • 1: 88200 Hz .
  • 2: 64000 Hz
  • 3: 48000 Hz
  • 4: 44100 Hz
  • 5: 32000 Hz
  • 6: 24000 Hz
  • 7: 22050 Hz
  • 8: 16000 Hz
  • 9: 12000Hz
  • 10: 11025 Hz
  • 11: 8000 Hz
  • 12: 7350 Hz
  • 13: Reserved
  • 14: Reserved
  • 15: frequency is written explictly

使用在线网站查看AAC Header

FF F1 51 80 2E 7F FC 21

Bits1111111111110001010111001000000000101110011111111111110000100001
IDMPEG-4
MPEG Layer0
CRC checksum absent1
ProfileLow Complexity profile (AAC LC)
Sampling frequency22050
Private bit0
Channel configuration2
Original/copy0
Home0
Copyright identification bit0
Copyright identification start0
AAC frame length371
ADTS buffer fullnessVBR
No raw data blocks in frame0

FFmpeg生成AAC文件

ffmpeg -i input.mp4 -vn -c:a libdfk_aac -ar 44100 -channels 2 -profile:a aac_he_v2 target.aac

  • -i 代表输入的文件
  • -vn代编 video not,不生成视频
  • -c:a代表codec:a,音频解码器为libdfk_aac
  • -ar 代表audio rate为44100
  • -channels为通道数
  • -profile:a 配置audio为aac_he_v2,

音频重采样

将音频三元组(采样率、采样大小和通道数)的值转换成另外一组值。其中任何一个值发生了变换都称为重采样,例如将44100/16/2  ---> 48000/16/2。

为什么需要重采样

  • 从设备采集的音频数据与编码器要求的数据不一致
  • 扬声器要求的音频数据与要播放的音频数据不一致
  • 更方便运算(在回音消除时,将多声道转化为单声道)

ffmpeg重采样的步骤

  • 创建重采样上下文
  • 设置参数
  • 初始化重采样
  • 进行重采样 

    api:

  • swr_ alloc_ set_ opts
  • swr_init
  • swr_convert
  • swr_free

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

顾文繁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值