xiph / flac

Free Lossless Audio Codec
https://xiph.org/flac/
GNU Free Documentation License v1.3
1.63k stars 277 forks source link

Converting WAV to FLAC while preserving TAGS #496

Closed pcar75 closed 1 year ago

pcar75 commented 1 year ago

Hi,

I have a collection of music in WAV format (mostly std, 16b, 44.1 kHz), where many pieces were digitized with Audacity or VLC Player or a DAW, filling in some TAGS. As WAV format does not strongly support TAGS and is bulky, I'm considering mass transferring them to FLAC format and preserving the TAG values already present.
The flac (v1.4.1) --keep-foreign-metadata or --keep-foreign-metadata-if-present do not save TAGS and a warning appears when used (yet).

My test process so far is : 1) Use Mp3Tag.exe (v3.18) to select all WAV files and superficially mass-cleanse the TAGS. 2) Export the list to .csv text file (ex.: Wav2FlacList.csv , whose lines contains PathFilename;Title;Artist;Album;Track;Year;Genre;Comment;). 3) Edit the list to initialize TAGS without value with - (dash or any value/string you deem appropriate). 4) Use the list with Xiph.org flac.exe under Windows10 CMD (with EXTENSIONS enabled) like so ... FOR /F "tokens=1-8 delims=;" %A in (Wav2FlacList.csv) DO flac --preserve-modtime -T "TITLE=%B" -T "ARTIST=%C" -T "ALBUM=%D" -T "TRACK=%E" -T "YEAR=%F" -T "GENRE=%G" -T "COMMENT=%H" "%A"

Note that step 3) is necessary because whenever one of the FOR tokens is empty (i.e. a TAG contains nothing) , it shifts the remaining tokens to the left so that if YEAR is missing but GENRE has value "Rock" the resulting flac file TAGS will have YEAR as "Rock", GENRE as whatever COMMENT contained and COMMENT will be empty.

EDIT: With more testing , there are functions, actions and scripting facilities in Mp3Tag, so step 3) can also be done entirely in Mp3Tag, before exporting the list (step 2).

So, pending better working TAG preserving options and short of assigning values to each and every TAGS of every file or programming something special, this is the best hack I came up with so far.

Hope it helps somebody ;-)

ktmf01 commented 1 year ago

Hi,

I have a collection of music in WAV format (mostly std, 16b, 44.1 kHz), where many pieces were digitized with Audacity or VLC Player or a DAW, filling in some TAGS. As WAV format does not strongly support TAGS and is bulky, I'm considering mass transferring them to FLAC format and preserving the TAG values already present.

If you would like to 'transcode' tags from WAV to FLAC, I'd recommend using ffmpeg, which understands many different tag formats and can copy tags between formats.

The flac (v1.4.1) --keep-foreign-metadata or --keep-foreign-metadata-if-present do not save TAGS and a warning appears when used (yet).

Please describe in more detail what warnings appears, and what --keep-foreign-metadata doesn't do what you expect it to do. It doesn't copy the tags to FLACs own Vorbiscomment format, but it should keep them as foreign metadata. It that doesn't work, it should be fixed.

pcar75 commented 1 year ago

@ktmf01 , Thanks Martijn.

FFmpeg seems quite capable although complex . I may look more into it but my hack will write the tags in the FLAC format most music player will recognize. Windows, Audacity, VLC, Mp3Tag do not recognize RIFF INFO tags in a FLAC file, which is what --keep-foreign-metadata provides.

As for the FLAC warning, it is NOTE: --keep-foreign-metadata is a new feature; make sure to test the output file before deleting the original.

ktmf01 commented 1 year ago

Hi @pcar75,

I'm still curious why TAGS isn't preserved by --keep-foreign-metadata, because it should. Could you attach the output of running metaflac --list on a WAV file with tags that you've encoded with --keep-foreign-metadata, so I can see what happens?

pcar75 commented 1 year ago

Tags ARE preserved in the flac file, they are just ignored with other software I use (see above).

Metadata saved in flac file.txt

ktmf01 commented 1 year ago

OK, so this is not really a FLAC issue in my opinion. At least, not as long as there isn't an agreed upon standard for tags in WAV files.

For anyone reading this, I recommend using ffmpeg, which understands many different tag formats. Simply use

ffmpeg -i somefile.wav somefile.flac

for the conversion. If you want to do a lot of files on Windows, place ffmpeg in your path or working directory and do

for /r %i in (*.wav) do ffmpeg -i %i %~ni.flac

on *nix you can do


find . -iname \*.wav | while read FILE; do ffmpeg -i "$FILE" "${FILE%.wav}.flac"; done