Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Can a file be restored to original format after compression by FLAC? (Read 999 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Can a file be restored to original format after compression by FLAC?

Our company receives files in the following format's: .wav, .aiff, .mp3. I need to ensure the original file is backed up in it's original file format and archived. If I take one of those same and use FLAC for file compression, can I uncompress the file and get it back to the original file format?

Re: Can a file be restored to original format after compression by FLAC?

Reply #1
Depends.
If the format is lossless ( WAV, AIFF) you can convert it to FLAC (lossless compression) and decode it back to any lossless format of choice without loss.

If you convert MP3 or any other lossy format to FLAC, you first have to decode it to linear PCM than apply the lossless compression. This will be sound quality wise equal to the originating MP3.
However, it you convert the FLAC to MP3, you apply lossy compression for a second time and this will yield generation loss. Won't say it is dramatic but it certainly is not the original MP3.
TheWellTemperedComputer.com

Re: Can a file be restored to original format after compression by FLAC?

Reply #2
Our company receives files in the following format's: .wav, .aiff, .mp3. I need to ensure the original file is backed up in it's original file format and archived. If I take one of those same and use FLAC for file compression, can I uncompress the file and get it back to the original file format?
Hi,
you should not "compress" MP3 using FLAC! FLAC is a linear format, this means the information of a WAV or AIFF is stored without losses. MP3 has undergone some serious calculations to replace (hopefully!) inaudible content by quantisation noise. In extent, a FLAC file created out of an MP3 will be much bigger than the original MP3.
So, there is absolutely nothing wrong with compressing linear audio like WAV or AIFF into FLAC, but lossy data-reduced files like MP3, M4A, AAC will grow in size and cannot be restored to the original.

haha ... @Roseval was faster

Re: Can a file be restored to original format after compression by FLAC?

Reply #3
I think that the point to be made is that in order to convert it to flac, the mp3 will be decoded to wav format and then compressed. Not what you're after. The best back up copy of an mp3 file is a simple copy, you cannot improve on the compression without further data loss.

Re: Can a file be restored to original format after compression by FLAC?

Reply #4
with wav and aiff, yes you can do that, given the bit depth of the tracks is 24 bit or lower. If it is 32 bit you can use wavpack.
With mp3 you do not need to convert to flac in the first place. File size would be larger anyway AND what is way more tragic is that you will be forced to decrease audio quality if you ever want to lossily compress that file again.

Re: Can a file be restored to original format after compression by FLAC?

Reply #5
I need to ensure the original file is backed up in it's original file format and archived. If I take one of those same and use FLAC for file compression, can I uncompress the file and get it back to the original file format?
MP3: keep them as they are. The .mp3 is the "original" then.

AIFF and WAVE: FLAC is an audio compressor. Even if it has options to preserve RIFF/IFF chunks for later restoration, it is not made for preserving non-audio parts of input.
Also if you receive floating-point files, FLAC has no option to handle those signals.

WavPack can handle both these items: (1) when you need full bit-by-bit restoration of the input file with all non-audio chunks in the very same order, and (2) signals could be 32-bit floating-point stored in WAVE or AIFF. It is also open source and well-specified and generally a safe bet.

(64-bit audio in WAVE or AIFF? You are out of luck, I don't think there is anything that handles it. Maybe if you pay the WavPack dev to extend the format. He has resisted so far, for good reason.)

Re: Can a file be restored to original format after compression by FLAC?

Reply #6
I need to ensure the original file is backed up in it's original file format and archived.
I'm looking at this with a QA hat on, as you say this is business rather than hobby.  May I presume you need verifiable traceability?  I assume you have customers who would be very upset if it later turned out the data you had archived could not be restored to the original.

If so, you cannot take on trust that any form of audio compression will necessarily recreate the original file when decompressed.  Any specific example might, but that cannot be taken as extending to the general case unless you are in possession of some kind of auditable specification which states x ≡︎ decompression(compression(x)) AND y ≡︎ compression(decompression(y)).

The problem is this: any form of audio file is a representation of the bit streams for the (potentially multiple) sound channels, and the process of creating that representation requires the original bit streams as input.  In order to take the audio file and convert it to a new representation (eg MP3 to FLAC), you first have to extract the bit streams from the MP3, and process them through FLAC.

While it might be possible to de-FLAC and obtain the bit streams which originally went into the FLAC, it is not possible to recreate the original MP3 from those bit streams.

In symbolic terms:

input.mp3 –> deMP3 –> input.bitstream –> FLAC –> archive.flac –> deFLAC –> output.bitstream –> MP3 –> output.mp3

Supposing you are willing to accept x ≡︎ deFLAC(FLAC(x)), then input.bitstream ≡︎ output.bitstream, and that might be sufficient to satisfy your business case, but y ≢︎ MP3(deMP3(y)) so output.mp3 ≢︎ input.mp3 so it might be difficult to satisfy your customers that your archive is valid.

In the above, substitute any other encoding for MP3.  The question is "is it reversible?".  WAV yes, anything else is a definite "maybe", and what certainty is there that even lossless FLAC is bit-perfect reversible?

I'm not talking about "sounds identical", I'm talking about being able to run a binary compare on two files and verify they are identical.  Only if you show that, for each case, output.mp3 ≡︎ input.mp3, can you keep archive.flac and throw away input.mp3, and even then you would also have to archive the reconstruction process – you would not be able to update software and assume it worked the same.

There is no point taking all this risk for an audio file which is already compressed (eg MP3).  The storage space gain is too minor to be worth it.  What you could do is ZIP it, which has the benefit of preserving file properties (eg the original file name) in an auditable package (and ZIP is demonstrably reversible).

On the other hand, there are significant storage space gains to be made for uncompressed audio.  As discussed in previous posts, there may be better alternatives than FLAC... but whatever you use you will want to obtain some kind of documentary evidence that your archival process does recreate the original file.  And then ZIP it.
It's your privilege to disagree, but that doesn't make you right and me wrong.

Re: Can a file be restored to original format after compression by FLAC?

Reply #7
you cannot take on trust that any form of audio compression will necessarily recreate the original file when decompressed.
WavPack was created specifically for that purpose - compressing .wav files and getting them back, not only the audio but the file.
(You need to use the official tool - ffmpeg has no such ambition.)

WavPack recently got AIFF support with same full restore, and can do the same to PCM in CAF - and it also supports floating-point WAVE/AIFF/CAF files, float are sometimes exported from DAWs. Including the legacy CoolEdit float format.


Also Monkey's Audio does full restore (I don't even think it can be switched off!), TAK and OptimFROG and I think MPEG-4 ALS work the same way.

For this purpose I recommend WavPack, it being the multi-platform FOSS with a format specification and more formats supported (except AU/SND). Furthermore, it has since long been able to handle certain not-uncommon malformed input files and restore them, most significantly, "4 GiB .wav files": https://hydrogenaud.io/index.php/topic,122222.0.html

(IIRC there is a corner case where WavPack will return something else than fed - non-compliant DSD files not terminated correctly I think it was?)

Re: Can a file be restored to original format after compression by FLAC?

Reply #8
So long as WavPack has auditable documented pedigree, I concur.  But that's not taking on trust.  Hear-say or random ad-hoc tests (ie "trust") are not sufficient (in a quality assurance situation).

Nonetheless, even if:

deMP3(input.mp3) = deWAVPACK(WAVPACK(deMP3(input.mp3)))

[which might be sufficient for the OP's purpose]

input.mp3 ≢︎ MP3(deWAVPACK(WAVPACK(deMP3(input.mp3))))

[which might be required if it were essential to verifiably reproduce an original .mp3 (or other lossy input), because MP3 is not a reversible process.]

The above inequality does not apply if "MP3" (as per the input file as received from the client) is substituted with a reversible encoder.

But. as stated above, what would be the point of WavPacking an MP3 anyway?
It's your privilege to disagree, but that doesn't make you right and me wrong.

 

Re: Can a file be restored to original format after compression by FLAC?

Reply #9
No, WavPack does not take on MP3.

... well actually you can try to treat input files as raw, but there is no sense to that. Keep MP3 files as they are.