I have a load of audio files (about 1000) which I want to convert from m4a to mp3 so I can use play them on a CD player which has a USB port.
I tried doing something simple like: ffmpeg -i FILE.m4a FILE.mp3 but this seems to reduce the bitrate to a very low value, which isn't what I want.
Similarly I don't want to convert using a constant bitrate, such as 320k, because some of the files I am converting are 320k m4a's and some are as low quality as 96k m4a's.
It seems to make no sense to force 320k, since some files will become many times larger than they need be. Similarly it makes no sense to destroy all my 320k files by converting them to something much lower than 96k. (At the moment, the files are being converted to about 50k.)
Does anyone know how I can do this? What I really want to do is tell ffmpeg to convert all m4a files in a directory into mp3's while retaining the current audio quality as best it can. (Of course there is likely to be some extra losses from converting from lossy to lossy file formats, above that which would be expected when converting from a lossless to lossy format.)
Thanks for your help. If this isn't possible, is there some sort of script which might detect the required quality as it converts files individually?
PS: I am working on an intel Mac, but also have a Ubuntu box.
6 Answers
Use Variable Bit Rate (VBR)
You can use the -q:a option in ffmpeg to create a variable bitrate (VBR) MP3 output:
ffmpeg -i input.m4a -c:v copy -c:a libmp3lame -q:a 4 output.mp3What -q:a values to use
From FFmpeg Wiki: MP3:
Control quality with
-q:a(or the alias-qscale:a). Values are encoder specific, so for libmp3lame the range is 0-9 where a lower value is a higher quality.
- 0-3 will normally produce transparent results
- 4 (default) should be close to perceptual transparency
- 6 usually produces an "acceptable" quality.
The option
-q:ais mapped to the-Voption in the standalonelamecommand-line interface tool.
You'll have to experiment to see what value is acceptable for you. Also see Hydrogen Audio: Recommended LAME Encoder Settings.
Encoding multiple files
In Linux and macOS you can use a Bash "for loop" to encode all files in a directory:
$ mkdir newfiles
$ for f in *.m4a; do ffmpeg -i "$f" -codec:v copy -codec:a libmp3lame -q:a 2 newfiles/"${f%.m4a}.mp3"; done 2 Use FFmpeg command line version.
MP3 is officially discontinued (from 2017) and obsolete codec (I call it a dead now). World has already switched to AAC (more efficient & quality codec), and everyone should use this, instead of mp3:
ffmpeg -i filenameee.m4a -acodec copy output.aacUpdate: Even though I don't recommend that, unfortunately, some low-quality and obsolete hardware developers still produce appliances which use mp3 and some people still request for that format... Well, here it is:
ffmpeg -i filenameee.m4a -acodec libmp3lame -ab 256k output.mp3 3 This worked for me:
ffmpeg -i testing.m4v -b:a 192K -vn testing.mp3 Using existing answers as a basis I wrote a bash script which should do exactly what the question asks on an Ubuntu machine (tested on 16.04). You'll need to install avprobe which is in the libav-tools package. You can install avprobe with the following command
sudo apt-get install libav-tools
NOTE: It would be wise to make a backup of any folder in which you run this script as well as make your best effort to read and understand what it is doing before running.
I have not tested very rigorously so YMMV.
#!/bin/bash
mkdir "mp3s"
for f in *.m4a;
do bitrate=$(avprobe "${f}" 2> >(grep bitrate) | sed 's/^.*bitrate://g' | sed 's/[^0-9]*//g') bitrate="${bitrate}K" new_filename=$(echo "${f}" | sed 's/.m4a$/.mp3/g') ffmpeg -y -i "${f}" -acodec libmp3lame -ab "${bitrate}" "mp3s/${new_filename}"
done 1 My m4a file wouldn't convert with ffmpeg at all(generating unreadable mp3 file roughly the same size as m4a). For it me it worked to use vlc for conversion:
- Media ->
- Convert\Save ->
- Select file ->
- Convert file ->
- Choose profile "Audio mp3) ->
- press wrench button near profile ->
- Select Audio codec and edit 128kbps to 320 ->
- press save ->
- Enter output filename ->
- Start
If you work at 48 KhZ and at least 24-bit in the input file (from a file editor i.ex.) -q:a 0 will reproduce the 20 kHz at no so large file as flac... But low quality audio unless you reduce the noise from high frequencies (hiss) by dithering or nose reduction audio editors, created in conversions, that will be reproduced, then will use data file as a inaudible HF, but expensive noise.