Why is a FLAC encoded from a decoded MP3 bigger than the MP3?

13

3

To be more precise than in the title, suppose I have a MP3 file that is 320 kbps. If I decompress it, then logically, all the data except for roughly 320 kilobits out of each second of audio should be redundant data, able to be compressed away. So, when I encode the decompressed file to FLAC, or any other lossless codec, why is it so much larger?

On a related note, is it theoretically possible to losslessly recover the source mp3 audio from a decompressed wav? (I know the mp3 itself is lossy. I'm asking if it's possible to re-encode without any further loss.)

EDIT: Let me clarify the related question, and the rationale behind it. Suppose I have a wav that was decompressed from an MP3 file (and assume I don't have the mp3 itself for some reason). If I don't want to lose any more quality, I can re-encode it with FLAC or any other lossless encoder and get a larger file just to maintain the same quality. Or, I can re-encode it to mp3 again and get the same size as the original but lose more data. Obviously, neither of these cases is ideal. I can either have the original size or the original quality, but not both (I mean the quality of the original mp3, not the original lossless source). My question is: Can we get both? Is it theoretically possible to recover the lossy compressed data from the lossy decompressed data, without losing even more?

If it is possible, I could imagine a lossless compression algorithm that compresses the audio with FLAC. Then it also scans the audio for any signs of previous lossy compression, and if detected, recompresses it losslessly to the original lossy file. Then it keeps whichever file is smaller.

Ryan C. Thompson

Posted 2009-10-30T06:16:01.933

Reputation: 10 085

Simple, MP3 is compressed, FLAC is uncompressed. When you convert, it Uncompresses the MP3 data. – Moab – 2012-06-02T16:12:32.840

2That is wrong. FLAC is an audio compression format. – Ryan C. Thompson – 2012-06-03T15:12:59.077

here's my favorite guide to ripping and encoding audio. enjoy, it's an excellent read: http://mp3.radified.com/

– None – 2009-10-30T06:23:18.907

2The decoder does not simply pad the 320kb up to 1411kb with meaningless bits, the bitrate of a PCM file is given by the bit-per-sample value, the number of channels and the sampling rate. For standard CD audio this is (2 channels)(44.1KHz sample rate)(16 bits-per-sample) = 1411kbps. – skelly – 2009-10-30T07:22:04.093

Answers

31

The reason the FLAC is larger than the MP3 of the same data is because they encode differently. :) MP3 just encodes perceptual information, while FLAC stores every single speck of data, just in a more compact format.

  • Converting a WAV to a FLAC is like converting a BMP to a PNG.
    • Same exact pixels, but compressed losslessly like a ZIP file into a smaller size.
  • Converting a WAV to an MP3 is like converting a BMP to a JPEG.
    • Instead of storing exact pixels, it's really storing instructions for generating squares with ripples of color that look kind of like the original.

Similarly, MP3 just stores instructions for generating ripples that, when added together, sound kind of like the original. But the difference between the true signal and the generated signal (the error signal) consists of random noisy artifacts, like JPEG jaggies. When you then store this in a perfectionist format like FLAC, it needs to store all those jaggies, and random noise is harder to compress losslessly, so it increases the size of the file. (Truly random noise is incompressible. When you compress a file losslessly, you're eliminating redundant repeating patterns and making it look more like random noise.)

I bet if you convert the JPEG to PNG you will see the same kind of increase in size as you see when converting MP3 to FLAC, since the perfectionist lossless codec needs to remember every little jaggy and artifact that wasn't in the original bmp.

This analogy isn't perfect, since audio is more like a photo than a line-art diagram, but it helps get the idea across:

Original BMP size: 29 kB

Blue dots in PNG form

PNG size: 629 B

Blue dots in JPEG form with jaggies

JPEG size: 1.7 kB

Blue dots with jaggies re-encoded to PNG

PNG created from JPEG: 6.2 kB

endolith

Posted 2009-10-30T06:16:01.933

Reputation: 6 626

Ok, so I guess this raises a related question: in the example, is it possible to recover the exact 1.7 kB JPEG from the 6.2 kB PNG? By analogy, can an original lossy audio file be recovered from its decoded form? – Ryan C. Thompson – 2010-03-18T18:14:02.613

Well, the 6.2 kB PNG contains exactly the same information as the 1.7 kB JPEG, but I don't think you could recreate the original JPEG through the normal encoding process. You could probably write an analyzer to figure out what the original JPEG was, though, by doing a DCT of each 8x8 square. But there might be variants of the JPEG format that give multiple ways to encode the same pattern, so I don't know. – endolith – 2010-03-22T16:51:21.040

I think it would be possible, in theory, to create a program that does the exact reverse of what the MP3 encoder did, if it knew exactly what encoding algorithm was used, and what settings were used, it would then just do the opposite thing. However, there is not one ultimate "MP3 encode" algorithm -- each encoder program may do something slightly different. So in practice, this is not possible to do. – Kevin Panko – 2010-03-31T20:49:18.447

It's not possible, even in theory, to do the exact reverse of what the MP3 encoder does, because the MP3 encoder throws away information in the process. That's why it's called "lossy compression". The information is lost and can never be recovered from the encoded file. The best you can do is decode it. If you know the encoder settings, you can probably tweak the decoder a little to get a slightly more accurate representation, but it will never be perfect. – endolith – 2010-04-01T17:49:01.870

1You are right. I don't know what I was thinking. – Kevin Panko – 2010-04-27T22:58:03.233

3But of course once a file is converted to JPG, data is lost, and can't be recovered by converting to PNG. If there's more data in the FLAC/PNG much of it will be fictitious. – pavium – 2009-10-30T06:38:04.400

1Yes. Meaningful data is lost, and erroneous data is created. – endolith – 2009-10-30T16:34:17.893

1That is clearly illustrated in endolith's example diagrams. – hplbsh – 2009-10-30T17:17:15.357

1This is an amazingly thorough answer. Nice job! – cowgod – 2009-10-30T20:47:15.947

1The line-art diagram analogy works if you are listening to Kraftwerk. – kinokijuf – 2013-01-27T15:32:29.143

2

When you decode an MP3, no matter what bitrate, you get standard 1411kbps/44100Hz 16bit (or whatever the source was) PCM audio that has all the noticeable and un-noticeable effects of the lossy encode process, this format is required for playback and encoding/re-encoding, any file of any codec is being decompressed when you play it on your computer, MP3 player, etc.

The FLAC encoder doesn't care if the audio it's compressing came from a decoded MP3 or a brand new CD, it will simply reduce the size of the source file without any change to the audio data, making a full recovery of the source possible, a lossless process.

A FLAC file made from an MP3 will sound exactly like the MP3, a FLAC file made from a CD track will sound exactly like the CD.

skelly

Posted 2009-10-30T06:16:01.933

Reputation: 664

0

To answer part two, if you convert back to a WAV from the MP3, then pick a lossless encoder, you should have an identical-quality file when you're done.

As to why the FLAC is bigger than the MP3, you're taking one of the more-compressed formats, decompressing it, then recompressing it in a less-efficient compression tool (though with a higher-quality of playback).

It's kind of like asking why converting a JPG to a PNG makes it bigger - you're [partially] decompressing the file, then recompressing in a lossless way. FLAC, like PNG, isn't optimized for space, but for quality.

warren

Posted 2009-10-30T06:16:01.933

Reputation: 8 599

FLAC (and PNG) are lossless, so saying that those are optimized for quality don't make sense. – Joakim Elofsson – 2009-10-30T17:01:35.950

3@Joakim: lossless == max quality, so lossless formats are optimized for quality by definition. – quack quixote – 2009-10-30T19:43:46.123

2that's my point, by definition so there is no optimization. if the defintion is max quality, then there is nothing to optimize – Joakim Elofsson – 2009-10-31T00:34:58.903

0

mp3 reqiures a decoder to be playable, the result of the decoder is an approximation of the original track (usually from a CD), so the decoder adds data to make it playable (and this is not nonsense data). The resulting approximation got the same bitrate as the original track. Without decoding the mp3 the information makes no sense, so can not be converted to anything else (unless very similar encodeing, like stereo-mp3 to 2X mono-mp3). And FLAC and mp3 is not even close to similar. When decodig a FLAC the result is not an approximation of the orignal data encoded into FLAC, but it is the exactly same.

Joakim Elofsson

Posted 2009-10-30T06:16:01.933

Reputation: 2 056