Step 1: Install ffmpeg
If you don’t already have ffmpeg installed, you can do so with the following commands:
For Debian-based distributions (e.g., Debian, Ubuntu):
sudo apt update
sudo apt install ffmpeg
For Arch-based distributions (e.g., Arch Linux):
sudo pacman -Sy ffmpeg
Step 2: Navigate to the directory containing your MP3 files
Use the cd command to change to the directory where your MP3 files are located. For example, if your MP3 files are in a folder called “music,” you can navigate to it like this:
cd /path/to/your/music/directory
Step 3: Convert MP3 to M4A using ffmpeg
Now that you’re in the directory with your MP3 files, you can use ffmpeg to convert them to M4A. Use the following command:
for file in *.mp3; do
ffmpeg -i "$file" -c:v copy -c:a aac -strict experimental -b:a 192k "${file%.mp3}.m4a"
done
Here’s what this command does:
for file in *.mp3; do:
This loop iterates over all files with the ".mp3"
extension in the current directory.
ffmpeg -i "$file" -c:v copy -c:a aac -strict experimental -b:a 192k "${file%.mp3}.m4a"
: This ffmpeg command converts each MP3 file to M4A.
-i "$file"
: Specifies the input file (the current MP3 file in the loop).
-c:v copy
: Copies the video stream as is, without re-encoding.
-c:a aac
: Sets the audio codec to AAC, which is commonly used for M4A files.
-strict experimental
: Allows the use of experimental codecs.
-b:a 192k
: Sets the audio bitrate to 192 kbps. You can adjust this value to your preference.
"${file%.mp3}.m4a"
: Defines the output file name. It uses parameter expansion to replace the “.mp3” extension with “.m4a.”
Step 4: Execute the conversion
Run the command, and it will convert all the MP3 files in the current directory to M4A format. The converted M4A files will be created in the same directory.
This guide provides an easy way to batch convert MP3 files to M4A using the Linux terminal and ffmpeg. Remember to replace “/path/to/your/music/directory” with the actual path to your MP3 files, and you can adjust the codec, bitrate, and other options in the ffmpeg command as needed.