Content
Introductory
Our obtained music files may not be the most common mp3 format, but for example m4ain or in flac. This wouldn't be a problem at all, because most music players know many formats, so there's a good chance we can play our music. But what if your favorite player still doesn't know this format and you don't want to switch to another player app? In this case, it will be necessary to convert our files to a format that our player also supports.
This was also the case in my situation when I wanted to play one of my favorite movie music on my mobile with the already proven player, but the program did not recognize the m4a file format. I didn’t want to look for another player because of this, so the conversion remained.
In this tutorial, we will look at how to convert m4a music files to mp3 on Debian and Ubuntu systems by trying out several methods.
Preparing songs to convert
Before we get started, let’s compile our music files that we want to convert to mp3. Put them in a separate directory so you can convert them more conveniently later, even in batches.
In this example, I will illustrate this operation with songs from Oblivion (forgetting) in m4a format, which I have compiled into a separate directory:
Here you may want to say a word about the names of the files, as shown in the picture, the file names may contain spaces or other special characters. These should be renamed to "_" characters, for example. This step is optional, but you can work with files more conveniently later if, for example, you don't have to cite names in quotation marks / apostrophes, and so on. For my part, at least I like working with files if they don’t have special characters and spaces in their names.
The simplest way, for example, is to call in a cycle tr command you can rename them in one step:
for file in *; do mv "$file" "$(echo $file | tr ' ' '_')" ; done
The result:
You can then create a subdirectory called "mp3" to which the converted files will be placed, so you can manage them more conveniently if they are separate:
mkdir mp3
So with that, our music files are ready to go.
Convert music files from m4a to mp3
There are several options for converting between different audio formats, let’s see some of them now.
Convert with the ffmpeg command
Az ffmpeg command is a very powerful conversion tool that allows you to convert video and audio files between many formats. the ffmpeg To install the package, run the following command:
sudo apt-get install ffmpeg
To convert, run the ffmpeg operation on the very first file as a test while remaining in your music directory. So I have:
ffmpeg -i 01_Jack_s_Dream.m4a -acodec mp3 -ac 2 -ab 192k -loglevel error mp3/01_Jack_s_Dream.mp3
The switches and parameters for this command are as follows:
- -Yo: input file
- -acodec: codec to use for conversion
- ac: number of audio channels (eg stereo)
- ab: audio bit rate. Here, the 192 already produces pretty good quality. Of course, if the sampling of our source file is inherently weak, it won't get any better.
- -log letter: logging level. It's not neccessary. If we leave, it will write a lot of unnecessary things for us to the output. This switch has several setting levels, see the command for more information manual page we can find out. In the example, I chose the "error" level, so it only writes to the output if something goes wrong during the conversion.
- and finally we need to specify the output file.
For me, you converted this 1 minute 29 second number in about 2 seconds. Once we’re done, let’s check from a music player to see if it really became an mp3. Sure, it'll be good, but it's worth a try before we start batch conversion. If all goes well, you can also come up with a conversion of all your songs at once.
Batch conversion
If you have more than one file, it's a good idea to automate it here as well, just type in the file names one by one. We also use a for loop for this:
for file in *.m4a; do echo "Fájl konvertálása: $file " ; ffmpeg -i "$file" -acodec mp3 -ac 2 -ab 192k -loglevel error "mp3/${file%.*}.mp3" ; done
The command is arranged in several lines for clarity:
for file in *.m4a; do \
echo "Fájl konvertálása: $file " ; \
ffmpeg \
-i "$file" \
-acodec mp3 \
-ac 2 \
-ab 192k \
-loglevel error \
"mp3/${file%.*}.mp3" ; \
done
What happens here is essentially first clearing the name of the file to be converted in the loop to see where the operation is going, then running the ffmpeg command, replacing the names with the loop variables, and finally removing the file extension and ".mp3" extension. we will tie to the end.
I even added a timer to this, so the output is:
So he converted the whole album in 2 minutes 39 seconds (on an Intel I7-3770 processor). Of course if we convert on multiple threads at once, this operation can be significantly accelerated.
Finally, the completed mp3 files are in the appropriate directory:
They take up slightly less space compared to the previous 234 MB format.
Convert with the SoundConverter graphics application
For those who prefer to use the graphical interface, the SoundConverter application is the right choice, which is a small featherweight program, only about 1 MB of programs are downloaded when we run the sound converter package installation command from the terminal:
sudo apt-get -y install soundconverter
Prepare your music files in the m4a format to be converted, just like at the very beginning, and here it is advisable to use a separate mp3 subdirectory.
When we are ready, start the program from the "start" menu, in my LXQT desktop environment within the "Audio and Video" group called "Audio Converter":
Add files
Add your m4a or other format files that you want to convert. We can do this above Add a file button, or simply drag and drop files from another file manager window:
Beállítások
Click on Beállítások button, the settings panel will appear, where you can set everything in one place:
Here we set everything according to our own needs.
Where should the results go?
Here you set where you want to save the output files. I set up my mp3 subdirectory, which was also used for previous command line conversion.
You can also turn it on to delete the original files. I don't think it's worth using this, let's have the conversion ready first, and after we find the quality, etc., then delete the original files manually.
What should be the names of the files?
Here you can choose from several options. For example, the program can name the output files based on the artist, track title, etc. stored in the music files, or it simply keeps the original file names smooth and just replaces their extension - as we did before with the command line batch conversion. I choose the latter here as well.
You can also check to extract special characters from file names. We also did this at the beginning of the command line section.
Output type?
Finally, you can fine-tune the output file format settings:
- Format: mp3
- Bit rate mode: Permanent (CBR) You should choose this here, because with this setting, surely all players can play our created mp3 files. Variable bit rate mp3 files are slightly more optimal, but in this case, some players may not be able to open them.
- Quality: Here we choose the right one for us. The "High" setting comes with a bit rate of 192 kbps, so that's enough if you just want to listen to your music in a non-studio.
- Re-Sampling: Skip this, you don't need it.
- Force mono output: I don't think we want that to be mono either.
- Limit the number of parallel tasks: This is also left off and then the program will self-regulate to make the conversion go at optimal speed.
If you have them, click at the bottom of the panel Closure button.
Conversions
If we’re done with everything so far, the conversion can come. In the main window, click Conversions button.
This will start the conversion on several threads:
This performs the conversion of m4a files to mp3 significantly faster than the command line, which ran on only one thread. Moreover, even the state of progress of the process is much more spectacular here. Compared to the extremely small size of the program, it knows what you need and is also completely easy to use.
Conclusion
With these methods, we can easily convert our music to the right audio format. Although in this example we have converted m4a type files, with the two tools presented we can convert many other audio formats to suit our needs.
- To post registration and login required
- 164 views