Convert audio files to mp3 using ffmpeg

2019-01-29 18:01发布

I need to convert audio files to mp3 using ffmpeg.

When i write the command as ffmpeg -i audio.ogg -acodec mp3 newfile.mp3, I get the error:

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

I also ran this command :

 ffmpeg -formats | grep mp3

and got this in response:

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

I guess that the mp3 codec isnt installed. Am I right here ? Can anyone help me out here ?

10条回答
2楼-- · 2019-01-29 18:21

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

VBR Encoding:

ffmpeg -vn -ar 44100 -ac 2 -q:a 1 -codec:a libmp3lame output.mp3
查看更多
唯我独甜
3楼-- · 2019-01-29 18:23

If you have a folder and sub-folder full of wav's you want to convert, put below command in a file, save it in a .bat file in the root of the folder where you wan to convert, and then run the bat file

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"
查看更多
兄弟一词,经得起流年.
4楼-- · 2019-01-29 18:27

High quality for Mac OS works perfectly!

ffmpeg -i input.wma -q:a 0 output.mp3

查看更多
干净又极端
5楼-- · 2019-01-29 18:29

Never mind,

I am converting my audio files to mp2 by using the command:

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

This command works perfectly.

I know that this actually converts the files to mp2 format, but then the resulting file sizes are the same..

查看更多
成全新的幸福
6楼-- · 2019-01-29 18:31

A very complete list of ffmpeg arguments can be found here:

http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs

So you could use this command:

ffmpeg -i input.wav -vn -ar 44100 -ac 2 -ab 192k -f mp3 output.mp3

Explanation of the used arguments in this example:

  • -i - input file

  • -vn - Disable video, to make sure no video 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)

  • -ab - actually seems to be changed, so should be replaced for newer ffmpeg version to -b:a 192k Converts the audio bitrate to be exact 192kbit per second

  • -f - Force input or output file format. The format is normally auto detected for input files and guessed from the file extension for output files, so this option is not needed in most cases.

查看更多
smile是对你的礼貌
7楼-- · 2019-01-29 18:31

For batch processing files in folder:

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

This script converts all "wav" files in folder to mp3 files and adds mp3 extension

ffmpeg have to be installed. (See other answers)

查看更多
登录 后发表回答