Ideally, I want to convert from MP3 to FLAC and back. I also need to be able to script this.
The fundamental tool for sound format conversions and simple transformations is SoX, the Swiss Army knife of sound-processing programs.
If you're running Debian, support for writing MP3 in
sox version 13 and up supports FLAC, along with many other formats. sox can do many things to an audio file, not just convert from one format to another. It is to audio what ImageMagick is to graphics.
Your first question is going from
This will use WAV headers, which has limitations when it comes to very long files (four hours or more long sound files, etc.)
Your second question is how to go from
These settings assume default quality levels, etc. Read the man page of
Now, it might just be, that you have very long recordings, which you then want to re-encode into a lossy format. This was one of my use cases, and I came up with this:
This assumes the raw format is a PCM data. Sample rate 48kHz, two channels. Each sample is 16bit, little endian, signed integer.
Encoding process of
It should be noted, that it makes no sense making a FLAC file out of an MP3 file, because the MP3 is already lossy encoded.
Going from MP3 -> FLAC and then FLAC -> MP3 makes no sense, as the quality will be impaired from the first, original MP3 encoding step.
However I assume you have a reasonable use-case for this...