我需要使用ffmpeg将音频文件转换为mp3。

当我把命令写成ffmpeg -i audio时。ogg -acodec mp3,我得到的错误:

FFmpeg version 0.5.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: 
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  built on Jun 24 2010 14:56:20, gcc: 4.4.1
Input #0, mp3, from 'ZHRE.mp3':
  Duration: 00:04:12.52, start: 0.000000, bitrate: 208 kb/s
    Stream #0.0: Audio: mp3, 44100 Hz, stereo, s16, 256 kb/s
Output #0, mp3, to 'audio.mp3':
    Stream #0.0: Audio: 0x0000, 44100 Hz, stereo, s16, 64 kb/s
Stream mapping:
  Stream #0.0 -> #0.0
Unsupported codec for output stream #0.0

我还运行了这个命令:

 ffmpeg -formats | grep mp3

得到的回应是:

FFmpeg version 0.5.2, Copyright (c) 2000-2009 Fabrice Bellard, et al.
  configuration: 
  libavutil     49.15. 0 / 49.15. 0
  libavcodec    52.20. 1 / 52.20. 1
  libavformat   52.31. 0 / 52.31. 0
  libavdevice   52. 1. 0 / 52. 1. 0
  built on Jun 24 2010 14:56:20, gcc: 4.4.1
 DE mp3             MPEG audio layer 3
 D A    mp3             MP3 (MPEG audio layer 3)
 D A    mp3adu          ADU (Application Data Unit) MP3 (MPEG audio layer 3)
 D A    mp3on4          MP3onMP4
 text2movsub remove_extra noise mov2textsub mp3decomp mp3comp mjpegadump imxdump h264_mp4toannexb dump_extra

我猜是mp3编解码器没有安装。我的思路对吗?


没关系,

我正在使用命令将我的音频文件转换为mp2:

ffmpeg -i input.wav -f mp2 output.mp3

这个命令非常有效。

我知道这实际上将文件转换为mp2格式,但结果文件大小是相同的..


你可以使用这个命令:

ffmpeg -i input.wav -vn -ar 44100 -ac 2 -b:a 192k output.mp3

本例中使用的参数说明:

-i - input file -vn - Disable video, to make sure no video (including album cover image) is included if the source would be a video file -ar - Set the audio sampling frequency. For output streams it is set by default to the frequency of the corresponding input stream. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. -ac - Set the number of audio channels. For output streams it is set by default to the number of input audio channels. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. So used here to make sure it is stereo (2 channels) -b:a - Converts the audio bitrate to be exact 192kbit per second


我必须清除我的ffmpeg,然后从一个ppa安装另一个:

sudo apt-get purge ffmpeg
sudo apt-add-repository -y ppa:jon-severinsson/ffmpeg 
sudo apt-get update 
sudo apt-get install ffmpeg

然后转换:

 ffmpeg -i audio.ogg -f mp3 newfile.mp3

1) wav转mp3

ffmpeg -i audio.wav -acodec libmp3lame audio.mp3

2) ogg到mp3

ffmpeg -i audio.ogg -acodec libmp3lame audio.mp3

3) AC3 到 MP3

ffmpeg -i audio.ac3 -acodec libmp3lame audio.mp3

4) aac转mp3

ffmpeg -i audio.aac -acodec libmp3lame audio.mp3

批处理文件夹中的文件:

for i in *.wav; do ffmpeg -i "$i" -f mp3 "${i%}.mp3"; done

这个脚本将文件夹中的所有“wav”文件转换为mp3文件,并添加mp3扩展名

Ffmpeg必须安装。(见其他答案)


对于目标为190 VBR且文件扩展名为.mp3而不是.ac3.mp3的文件夹中的文件进行批处理,您可以使用以下代码

将.ac3更改为源音频格式。

Ffmpeg mp3设置

for f in *.ac3 ; do ffmpeg -i "$f" -acodec libmp3lame -q:a 2 "${f%.*}.mp3"; done

尝试FFmpeg静态构建链接

文档:https://www.johnvansickle.com/ffmpeg/

将静态构建驻留在服务器上的同一目录中

$ffmpeg = dirname(__FILE__).'/ffmpeg';

$command = $ffmpeg.'ffmpeg -i audio.ogg -acodec libmp3lame audio.mp3';

shell_exec($command);

https://trac.ffmpeg.org/wiki/Encode/MP3

的VBR编码:

ffmpeg -vn -ar 44100 -ac 2 -q:a 1 -codec:a libmp3lame output.mp3

如果你有一个文件夹和子文件夹里都是你想转换的wav,把下面的命令放在一个文件中,保存在你想转换的文件夹根目录下的。bat文件中,然后运行bat文件

for /R %%g in (*.wav) do start /b /wait "" "C:\ffmpeg-4.0.1-win64-static\bin\ffmpeg" -threads 16 -i "%%g" -acodec libmp3lame "%%~dpng.mp3" && del "%%g"

高质量的Mac OS工作完美!

Ffmpeg -i input.wma -q: 0输出。mp3


正如这里所描述的,输入和输出扩展将由ffmpeg检测,所以不需要担心格式,只需运行这个命令:

ffmpeg -i inputFile。ogg outputFile.mp3


我将解释如何转换webm到mp3的mac,我猜linux它也工作。

安装ffmpeg (mac)或sudo apt安装ffmpeg (linux) 创建shell脚本-打开文本编辑器,把以下代码放在里面:

#!/bin/bash

echo webm to mp3 converter! Work begins! 
for FILE in *.webm; do     
    echo -e "Processing file '$FILE'";
    ffmpeg -i "${FILE}" -vn -ab 128k -ar 44100 -y "${FILE%.webm}.mp3";
done;

这段代码将查看当前目录中所有扩展名为.webm的文件。

保存没有扩展名的文件(例如“my-converter”) 通过终端导航到创建的文件 通过输入命令:chmod 700 my-converter使文件成为executabe,现在将在同一目录下创建unix可执行文件(.sh)。 通过输入:./my-converter从终端执行文件,进程开始,你会在终端窗口中看到进程。

完成了。


似乎没有人使用find,它让您在一行上完成所有操作。基于这个答案和这篇文章

find . -type f -iname "*.webm" -exec bash -c 'FILE="$1"; ffmpeg -i "${FILE}" -vn -ab 128k "${FILE%.webm}.mp3";' _ '{}' \;

对于播客来说,128k对我来说已经足够了。你可以把这个参数调整到其他参数旁边:

-i - input file -vn - Disable video, to make sure no video (including album cover image) is included if the source would be a video file -ar - Set the audio sampling frequency. For output streams it is set by default to the frequency of the corresponding input stream. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. -ac - Set the number of audio channels. For output streams it is set by default to the number of input audio channels. For input streams this option only makes sense for audio grabbing devices and raw demuxers and is mapped to the corresponding demuxer options. So used here to make sure it is stereo (2 channels) -b:a - Converts the audio bitrate to be exact 192kbit per second

此外,这还说明了ffmpeg比特率参数的区别


使用之前的答案,这里是一个别名,通过将以下添加到.bashrc/.zshrc:

alias convert-aac="cd ~/Downloads && aac-to-mp3"

# Convert all .aac files into .mp3 files in the current folder, don't convert if a mp3 file already exists
aac-to-mp3(){
    find . -type f -iname "*.aac" -exec \
        bash -c 'file="$1"; ffmpeg -n -i "$file" -acodec libmp3lame "${file%.aac}.mp3";' _ '{}' \;
}

用法: Convert-aac (shell)

感谢https://stackoverflow.com/a/70339561/2391795, https://stackoverflow.com/a/12952172/2391795和https://unix.stackexchange.com/a/683488/60329