FFmpeg音频转码
FFmpeg输出MP3
- 查看参数,使用之前需要先下载安装libmp3lame
ffmpeg -h encoder=libmp3lame
Encoder libmp3lame [libmp3lame MP3 (MPEG audio layer 3)]:
General capabilities: delay small
Threading capabilities: none
Supported sample rates: 44100 48000 32000 22050 24000 16000 11025 12000 8000
Supported sample formats: s32p fltp s16p
Supported channel layouts: mono stereo
libmp3lame encoder AVOptions:
-reservoir <boolean> E...A.... use bit reservoir (default true)
-joint_stereo <boolean> E...A.... use joint stereo (default true)
-abr <boolean> E...A.... use ABR (default false)
- MP3的转换
ffmpeg -i input.mp4 -acodec libmp3lame OUTPUT.mp3
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.19.100
Duration: 00:00:30.32, start: 0.000000, bitrate: 397 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], 261 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'OUTPUT.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0(und): Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 libmp3lame
size= 474kB time=00:00:30.30 bitrate= 128.2kbits/s speed=43.5x
video:0kB audio:474kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.073364%
- 设置VBR参数
ffmpeg -i input.mp3 -acodec libmp3lame -q:a 8 output.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:30.33, start: 0.025057, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc58.35
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (mp3float) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp
Metadata:
encoder : Lavc58.35.100 libmp3lame
size= 280kB time=00:00:30.30 bitrate= 75.6kbits/s speed=52.7x
video:0kB audio:279kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.124486%
- 设置CBR参数
ffmpeg -i input.mp3 -acodec libmp3lame -b:a 64k output.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:30.33, start: 0.025057, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc58.35
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (mp3float) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 64 kb/s
Metadata:
encoder : Lavc58.35.100 libmp3lame
size= 237kB time=00:00:30.30 bitrate= 64.1kbits/s speed=40.3x
video:0kB audio:237kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.146728%
5.设置ABR参数
ffmpeg -i input.mp3 -acodec libmp3lame -b:a 64k -abr 1 output.mp3
Input #0, mp3, from 'input.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Duration: 00:00:30.33, start: 0.025057, bitrate: 128 kb/s
Stream #0:0: Audio: mp3, 44100 Hz, stereo, fltp, 128 kb/s
Metadata:
encoder : Lavc58.35
Stream mapping:
Stream #0:0 -> #0:0 (mp3 (mp3float) -> mp3 (libmp3lame))
Press [q] to stop, [?] for help
Output #0, mp3, to 'output.mp3':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
TSSE : Lavf58.20.100
Stream #0:0: Audio: mp3 (libmp3lame), 44100 Hz, stereo, fltp, 64 kb/s
Metadata:
encoder : Lavc58.35.100 libmp3lame
size= 264kB time=00:00:30.30 bitrate= 71.4kbits/s speed=40.9x
video:0kB audio:264kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.131777%
FFmpeg输出AAC
动态码率(VBR)的AAC的级别中有三种编码信息,分为:
- LC:Low Complexity AAC,这种编码相对来说体积比较小,质量稍差
- HE:High-Efficiency AAC,这种编码相对来说体积稍小,质量较好
- HEv2:High-Efficiency AAC version 2,这种编码相对来说体积小,质量优
FFmpeg支持AAC的三种编码器:
- aac:FFmpeg本身的AAC编码实现
- libfaac:第三方的AAC编码器
- libfdk_aac:第三方的AAC编码器
以上三种质量顺序为:libfdk_aac > aac > libfaac
- 转码为AAC音频,码率为160kbit/s
ffmpeg -i input.mp4 -c:a aac -b:a 160k output.aac
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.19.100
Duration: 00:00:30.32, start: 0.000000, bitrate: 397 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 480x208 [SAR 16:15 DAR 32:13], 261 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
handler_name : SoundHandler
Stream mapping:
Stream #0:1 -> #0:0 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
Output #0, adts, to 'output.aac':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.20.100
Stream #0:0(und): Audio: aac (LC), 44100 Hz, stereo, fltp, 160 kb/s (default)
Metadata:
handler_name : SoundHandler
encoder : Lavc58.35.100 aac
size= 606kB time=00:00:30.30 bitrate= 163.7kbits/s speed= 66x
video:0kB audio:597kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 1.496385%
[aac @ 0x7fdc93027800] Qavg: 506.964
- 设置VBR参数(qscale:0.1~2)
ffmpeg -i input.wav -c:a aac -q:a 2 output.m4a
Input #0, wav, from 'input.wav':
Duration: 00:03:43.00, bitrate: 1411 kb/s
Stream #0:0: Audio: dts (DTS-ES) ([1][0][0][0] / 0x0001), 44100 Hz, 6.1, fltp, 1411 kb/s
Stream mapping:
Stream #0:0 -> #0:0 (dts (dca) -> aac (native))
Press [q] to stop, [?] for help
[aac @ 0x7fb289002e00] Using a PCE to encode channel layout "6.1"
Output #0, ipod, to 'output.m4a':
Metadata:
encoder : Lavf58.20.100
Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, 6.1, fltp, 463 kb/s
Metadata:
encoder : Lavc58.35.100 aac
size= 18773kB time=00:03:43.00 bitrate= 689.6kbits/s speed=21.4x
video:0kB audio:18735kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.205963%
[aac @ 0x7fb289002e00] Qavg: 236.000