0 Appending & splitting FLAC audio tracks not supported
Moritz Bunkus edited this page 2021-04-16 16:51:43 +00:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Appending & splitting FLAC audio tracks not supported

The situation

FLAC audio tracks cannot be appended or split with mkvmerge. Versions up to and including v44 did not actually emit error messages; however, the result was that the resulting FLAC tracks were invalid and could often not be played.

Starting with version 45 mkvmerge will refuse to append or split FLAC audio tracks and emit an error message instead.

Starting with version 47, the old behavior can be restored by adding --engage append_and_split_flac to mkvmerge's command-line options (in the GUI: multiplexer → "Output" tab → "Miscellaneous" → "Additional options"). Please note that this will result in broken tracks: the official FLAC tools will not be able to decode them and seeking will not work as expected.

Technical background

The FLAC format has a design that makes it hard to modify it without at least decoding the whole track. Modifying it requires re-writing most of the headers. Appending is only possible under very restrained circumstances (because certain header fields are used when decoding the frames like the minimum frame size in samples). The header even has seek tables that mkvmerge would have to modify.

On top of all that there's an MD5 checksum of the decoded data. Which means that modifying the tracks without decoding isn't even possible. In order to update the MD5 checksum mkvmerge would have to decode the whole stream.

Decoding could, in theory, be done via libFLAC, the library mkvmerge uses already for parsing the headers. libFLAC's design, though, makes that completely impossible. libFLAC (both the C and C++ variants) have exactly one function for decoding data, and it uses a pull model: libFLAC will call a "read callback" function that you provide in order to read more data.

As soon as your read callback returns anything other than success libFLAC thinks that the end of the stream has been reached. If you call that decoding function again then it won't work.

What this means is that libFLAC's design is 100% incompatible with mkvmerge's design.

So basically in order to support appending and splitting FLAC tracks I would have to implement my own FLAC decoder, something I'm not willing to do.

Categories: merging