Gangmax Blog

在Ubuntu上从mp4文件中提取音频并转换为mp3格式

废话不多说,命令如下:

1
2
mplayer -ao pcm ./a.mp4 -ao pcm:file="outfile.wav"
lame -h -b 192 outfile.wav a.mp3

原文来自这里。虽然我没有尝试,但是该命令貌似应该支持其它视频格式(比如avi)。命令行真是强大啊!


Added on “2021-09-17”.

From here. The method above uses “mplayer” while the current method uses “ffmpeg” which is more common.

1
2
3
4
5
6
7
8
9
# 1. For FFmpeg with Constant Bitrate Encoding (CBR):
ffmpeg -i video.mp4 -vn \
-acodec libmp3lame -ac 2 -ab 160k -ar 48000 \
audio.mp3

# 2. Use Variable Bitrate Encoding (VBR):
ffmpeg -i video.mp4 -vn \
-acodec libmp3lame -ac 2 -qscale:a 4 -ar 48000 \
audio.mp3

Comments