[flac-dev] Looking for users of --keep-foreign-metadata

Martijn van Beurden mvanb1 at gmail.com
Wed Nov 2 12:48:20 UTC 2022


Op ma 31 okt. 2022 om 01:37 schreef brianw <brianw at audiobanshee.com>:
> - There is a generally-accepted industry practice concerning these extra chunks that points out that it's problematic to preserve all types of chunks when editing the audio. For example, a visual overview or a cue list might easily become incorrect if the audio is changed. Of course, there are some chunks that can always be preserved, like original recording date, name of engineer, etc., but FLAC cannot know how to distinguish between the two types. My opinion is that FLAC should not suffer from this category of issues because the audio is specifically unchanged by the compression. Thus, it should be the case that all meta data can be preserved without risk, since the audio is also preserved exactly.
>

Perhaps FLAC should refuse to do operations like --skip or --until on
a file with foreign metadata embedded? I don't think it blocks that
currently.

What I think would be a nice option is pick the correct format
according to the stored foreign metadata. Currently, one can use flac
--keep-foreign-metadata somefile.aiff without problems, but flac
--keep-foreign-metadata somefile.flac will then fail because flac
tries to restore to wav by default. Also, there are the mentioned
problems with WAVE_FORMAT_PCM and WAVE_FORMAT_EXTENSIBLE. One possible
solution is adding an option --force-foreign-metadata-format (similar
to the --force-aiff-format, --force-rf64-format, etc. options) which
would then pick a format according to what is stored in the foreign
metadata. This could work two ways: it could simply instruct FLAC to
find which format should be written to, or it could instruct FLAC to
not construct any chunks of its own but exclusively use the stored
chunks.

>
> Reading your email question, Martijn, I think you might be asking whether FLAC should always preserve meta data - "restore ... bit-for-bit ... something that FLAC should strive for" - or leave this as an optional feature, so I want to comment on the two scenarios:
>

Considering being bit-for-bit accurate, I might be opening Pandora's
box here, but I think this should be dealt with properly, so I'll do
it anyway

The thing is, FLAC will store all chunks (except the contents of the
data chunk) on encoding, but currently ignores the master chunk, the
format chunk and the header of the data chunk on decoding. Usually the
result is still bit-for-bit the same (because there is usually no
ambiguity in how those chunks are formatted) but perhaps (I really
don't know, don't know whether such a thing is even possible) there
are cases where FLAC reconstructs something different than what is
stored. Choosing between WAVE_FORMAT_PCM and WAVE_FORMAT_EXTENSIBLE is
one such difference, but there might be others. That is why I'm
reaching out: perhaps the answer is obvious to people that use this
feature daily.

Perhaps an option --force-stored-foreign-metadata could be added to
have FLAC blindly use the foreign metadata chunks and data chunk
headers. I think this might result in invalid files (wrong chunk
sizes) in corner cases, for example when a FLAC file has been altered
(shortened/lengthened) but the chunks haven't been updated. I think
that might be the reason for the current behaviour.

> p.p.s. AIFF
> I cannot remember whether --keep-foreign-metadata works with AIFF

Yes, it does. It works with plain WAV and AIFF, and also with RF64 and Wave64.


More information about the flac-dev mailing list