0

I have MP3 files on which I need to perform some audio operations, then get them back to MP3. I know every operation degrades them a little bit, so my goal is just to minimize that.

I need to use both ffmpeg and SoX in series, because each program has some options that the other does not. As a result, I have ffmpeg output to WAV or FLAC, then SoX starts with that, performs its modifications, and outputs back to MP3. I assume that using a lossless format like WAV or FLAC for that middle step minimizes file degradation, compared with keeping them in a lossy format like MP3 through each step, because that would degrade from both the processing AND ALSO from saving to a lossy MP3. I also want to preserve the ID3 tags from the original file (especially track # and cover art, if possible, other fields don't matter too much).

I had been using WAV files, because they're lossless, but those lose the ID3 tags. I would then manually add the ID3 tags back. FLAC appears to keeps the ID3 tags and seems to work, but hard for me to know if it's as good at WAV for preserving the audio -- sounds good to me, but even if I can't hear the problem it might be there for those with better ears or if some files are marginal, even a small degradation could be enough to ruin it. I think FLAC, like WAV is also lossless, and so should be good for this, but that's what I'm trying to confirm.

Because it's only for the intermediate file that I have a choice of filetype and it's temporary (to be deleted after re-exporting back to MP3), the file size of the intermediate file doesn't matter at all, just the quality.

Questions:

  1. Am I correct that FLAC should work as well as WAV when output from ffmpeg with respect to audio quality, because both are lossless, for minimizing any audio loss as a function of the file format? (I can already see that it does work to maintain the ID3 tags)
  2. Are there any downsides to FLAC for this purpose or any other formats that would work better (e.g., I think AIFF, WMA, and a few other formats are also lossless and support ID3)?
  3. Am I right to think that using a lossless format as an intermediary at worst can't hurt, and may help, depending on the kind of changes being made to the file? If not, what else should I be considering?
  4. Do I need to worry about quality, bitrate, or anything like that for this intermediate file with a lossless format, or will ffmpeg automatically select the best options for those by default (I do have a specific destination bitrate and frequency for the final MP3 files that I must use at the end)?
1
  • What precisely is it you need to do to these files that needs you to go via two different apps? I'd be looking for a 1-app solution.
    – Tetsujin
    Commented Jun 29, 2023 at 8:08

1 Answer 1

1

Each audio process will change the sound anyway, so you need to do this at the highest possible bit- & sample-rate; even if your start & end formats are low-quality mp3.

You don't gain anything by upscaling, but you lose less as you process. Conversion to FLAC & back is itself lossless, but to preserve as much data as possible in your intermediates, you should consider converting to double your input sample-rate, at 32-bit. This may make quite large files even compressed, but you'll be discarding them anyway, afterwards.

4
  • To be sure I understand: if original MP3 is 44.1kHz, I should have ffmpeg convert it to 88.2kHz and 32bit FLAC. Then SoX starts with that, and exports back to 44.1kHz, MP3? Do I need to specify a codec (-c), or will ffmpeg pick the best one to convert to FLAC if I use "-f flac" option or just have an output file that ends in .flac? something like (not worrying about other parameters here, just the ones for round trip from and back to MP3): ffmpeg -i <input file.mp3> -sample_fmt s32 -ar 88200 <temp file.flac> and then: sox <temp file.flac> -c 2 -C 192 -r 44100 -b 16 <output file.mp3> Commented Jun 29, 2023 at 17:30
  • 1
    "88.2kHz and 32bit FLAC" Yes. It just gives you headroom for the processing. Most regular DAWs work at 64-bit float internally anyway. idk how ffmpeg or sox deal with these things, they both appear to be hammers & consider everything a nail. Your final output is whatever you want it to be. You're going to lose at that point anyway, no way to avoid it.
    – Tetsujin
    Commented Jun 29, 2023 at 17:35
  • Is there any advantage to push ffmpeg all the way up to 64bit? I assume that moving from 16 to 32 already gives all the headroom needed (even 24bit would probably be enough) and beyond that it's just adding processing effort with no benefit? Also, did you see my question on codec -- do you know if I need to specify that in ffmpeg for converting to FLAC? Commented Jun 29, 2023 at 17:42
  • 1
    I think 64-bit is probably overkill coming from mp3. I really don't know much about ffmpeg, sorry, or how or why to specify parameters. I'm a pro audio engineer, but I work in wav or aif & 'proper' DAWs most of the time, not 'coding' solutions, so they're not parameters I ever have to consider.
    – Tetsujin
    Commented Jun 29, 2023 at 17:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .