Convert WAV, APE, FLAC Music is MP3, M4A (MP4) format
Sometimes the music obtained is a non -destructive format such as APE or FLAC. If you are not particularly high in sound quality, in order to facilitate transmission and play on a variety of devices, sometimes they are converted to (high yards) MP3 format or M4A ( MP4 AUDIO) Format is more convenient. The following introduces the method of converting APE, FLAC, WAV, etc. under Linux into MP3 format.
First confirm that there are ffmpeg or Mac, LAME, and MP3SPLT tools in the system.arch linux packageSearch and install them. For FLAC and M4A formats, tools are also required: FLAC and FAAC.
For a APE/FLAC file, it is a song.
First restore the original audio as an uncomfortable Wave format
need to convert it to WAV format with FFMPEG or Mac or FLAC first, and then use Lame to convert WAV to MP3 format.
Assuming the song file name of the conversion is song.ape/song.flac, the command is as follows:
$ ffmpeg -i song.ape song.wav
or
$ mac -d song.ape song.wav
or
$ flac -d song.flac -o song.wav
This will get a song.wav file.
and then use a variety of encoding programs to compress Wave to MP3 or M4A
Use the lame command to compress to MP3:
$ LAME -V 0 SONG.WAV (Use VBR dynamic code rate compression, 0 indicates the highest quality, the default is 4, the lowest is 9)
or
$ LAME -B 320 SONG.WAV (using a fixed 320kbps code rate compression)
or, you can get the M4A (MP4) format file with FAAC encoding:
$ FAAC -W -q 100 song.wav -O song.m4a (100 represents the highest quality, if you choose 50, it means 50% quality)
Of course, you can also use FFMPEG compression to obtain the M4A format:
$ ffmpeg -I song.wav -Strict Experimental -C: A AAC -B: A 320K Song.m4a (FFMPEG built -in AAC encoder here, the set number is fixed 320K. The AAC encoder is still a experience version, there may be some problems)
If you compile FFMPEG, you also include other encoding libraries, such as libfaac, then you can:
$ ffmpeg -i song -c: a libfaac -q: a 100 song.m4a (let FFMPEG call libfaac compressing audio, the quality is set to 100)
$ ffmpeg -i song -c: a libfaac -b: a 320k song.m4a (let FFMPEG call libfaac compressing audio, use fixed code rate 320K compression, Note: In fact, it rarely uses fixed code rate to compress AAC)
can also be simplified to simplify the decompression and compression process into a step with FFMPEG. The command is as follows:
$ ffmpeg -i song.flac -ab 320k -map_metadata 0 song.mp3
Among them -MAP_METADADATA indicates the retaining meta data (ie, the song name, singer name and other information).
Batch processing
If a batch of APE needs to be converted, it is best to write a script batch processing, such as:
#!/bin/bash
for FILE in *.ape;
do
ffmpeg -i "$FILE" temp.wav;
lame -b 320 temp.wav "${FILE%.*}.mp3";
rm temp.wav
done
If it is a batch of FLAC files and want to retain metadata, the script is:
#!/bin/bash
for FILE in *.flac;
do
ffmpeg -i "$FILE" -ab 320k -map_metadata 0 "${FILE%.*}.mp3";
done
For a APE/FLAC file, it contains multiple songs
In this case, you will have a cue file. The cue file contains the album name of the APE/FLAC file, the singer name, and the name and time range of each song. We use the above method to convert the APE/FLAC file into the mp3 format, and then use the MP3SPLT tool to divide it.
Note: Sometimes the cue file we get may contain Chinese. In order to avoid garbled code, you can first check the contents of the inside to see if you can read it normally. Otherwise, you can change the file extension to TXT Change the various encoding formats until normal reading (Chinese use GB2312 or BIG5 coding), then copy the content that can be read normally and replace the original content of the file, and then change the file extension to Cue.
The commands of the MP3 according to the cue file are as follows:
$ mp3splt -c song.cue -o @[email protected] song.mp3
Among them @[email protected]indicates the format of the file name of the output.
- @a: Singer Name
- @b: album name
- @T: song title
- @n: Sound track number
and then get a series of MP3 files. This method is also suitable for FLAC format.
Finally, if you don’t want to knock on the command, you can also use the tool for free open source graphics interfacesoundconverter, as long as the GSTREAMER plugin is installed, it supports almost all audio formats.
Reference materials:
- FFmpeg and AAC Encoding Guide https://trac.ffmpeg.org/wiki/Encode/AAC
- Other programs such as FAAC, FLAC and LAME, because it is simple, you can directly view their Manual: $ Man Faac or $ Man Lame