【音频处理】工具(2)- ffmpeg音频操作指南

188 阅读1分钟

常用命令

1、音频格式转换

将wav转换成mp3:

ffmpeg -i from.wav dest.mp3

2、截取音频前多少秒

截取前3分20秒,即前200秒:

ffmpeg -i from.wav -t 200  dest.mp3

3、截取音频任意区域

可借助 -ss 和 -t 或 -to 参数来完成。下面以截取10秒到180秒音频来具体操作:

方法一:使用 -ss 和 -t 参数

  • -ss:指定开始时间,这里设置为 10 秒。
  • -t:指定持续时间,从第 10 秒开始截取 170 秒(180 - 10 = 170)的音频内容。
命令示例

在命令行中输入以下命令:

bash

ffmpeg -i input_audio.mp3 -ss 00:00:10 -t 00:02:50 output_audio.mp3
  • input_audio.mp3:你要处理的原始音频文件。
  • output_audio.mp3:处理后输出的音频文件。
时间格式说明

时间格式为 hh:mm:ss,例如 10 秒表示为 00:00:10,170 秒表示为 00:02:50

方法二:使用 -ss 和 -to 参数

  • -ss:同样指定开始时间为 10 秒。
  • -to:指定结束时间为 180 秒。
命令示例

在命令行中输入以下命令:

ffmpeg -i input_audio.mp3 -ss 00:00:10 -to 00:03:00 output_audio.mp3
  • input_audio.mp3:原始音频文件。
  • output_audio.mp3:输出的音频文件。