Repairing FLAC files

From Hydrogenaudio Knowledgebase

If a FLAC file is corrupted and you only want to save what exists, rather than re-rip from CD or re-acquire by some other method.

In Linux, for a single file:

metaflac --export-tags-to somesong.tags somesong.flac
flac -F -d somesong.flac
flac -f --best somsong.wav
metaflac --import-tags-from somesong.tags somesong.flac
rm somesong.wav somesong.tags

For multiple FLAC files:

Save the tags:

find -name "*.flac" -exec metaflac --export-tags-to '{}'.tags '{}' \;

Decode to WAV:

flac -F -d *.flac

Encode back to FLAC:

flac -f --best *.wav

Restore the tags:

find -name "*.flac" -exec metaflac --import-tags-from '{}'.tags '{}' \;

Cleanup:

rm *.wav *.tags