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: Problems muxing FLAC into matroska (Read 2988 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Problems muxing FLAC into matroska

HI,

our core developer Jory 'jcsston' Stone was fiddling a lot with FLAC audio in matroska currently, but encountering a lot of problems due to the way FLAC is embedded into its own framing.

He wrote here :

Quote
In case anybody didn't already know, I did add FLAC muxing to VDubMOD via
libflac. But it was buggy and slow because the only way to extract the
frames with libflac was to feed the decoder one byte at a time, storing the
data start and length whenever a decompressed frame was produced.
On top of that the timecodes were not always correct, some files would play
too fast others too slow. Same encode settings, same channel, sample rate,
bit-depth.

So I started a flac parser from scratch and made good progress until I hit
the UTF encoded integers.
http://flac.sourceforge.net/format.html

I have the code in the coreflac CVS if anybody wants to look at it.
http://corecodec.org/projects/coreflac/

See Ya,
Jory



Here my questions to you experts :

- Is there a more suitable lib than libflac if you dont want to decode a FLAC stream, but only plan to extract the data from its framing and mux into another container ?

- how was OggFLAC done ? Is there any specific lib for OggFLAC that is probably more suited for our purpose ?

- how about other lossless codecs like Wavpack or Optimfrog ? Do they have existing GPL libs that allow easy demuxing from their own framing ?

Thanks for you help anyhow ...

Christian

EDIT :

Shortly after having posted i realized that maybe our problem is not obvious for people who dont have a background in MKV :

Muxing any audio or video format into a MKV file, it is required by the specs to put exactly one frame of data into a single matroska block ( lacing or so-called 'timeslices' are exceptions to the rule, but following other strict rules instead ) and each block gets a timestamp, usually with a 1 ns precision ( scalable ).

So, to mux FLAC into MKV we need a parser who can read FLAC streams, finds out about the frame boundaries ( hopefully without having to decode the complete stream, to save CPU ) and then defines a complete matroska block with a timestamp that represents the playback starting time of this frame. It seems that libflac can not provide this type of information without having to decode the FLAC stream ( reminds us about Ogg somehow  ), and this is not very suitable for our purpose of muxing existing FLAC files into MKV for enhanced video editing.

Of course, this is no problem if we capture into MKV with a FLAC encoder filter, as then we can easily find out when a new frame starts, and put this into the MKV file together with the appropriate timestamp ( to come later).

Problems muxing FLAC into matroska

Reply #1
For the questions on utf8-style integer encoding in FLAC, refer him to the flac-dev list.  There's not enough info here for me to help.  I don't understand the timecode problem either.

As to extracting frames, it is true that you cannot find frame boundaries in a native FLAC stream without decoding.  Native FLAC was never intended to be a full-featured transport like that.  It's barely even a transport at all; without the sync code and sample counter a frame is just header+payload like Vorbis.

With Ogg (and hence Ogg FLAC) you can find the packet boundaries without decoding.  The FLAC->Ogg mapping puts exactly one FLAC frame (or metadata block) into one Ogg packet.  When you decode an Ogg FLAC packet with libOggFLAC you get one FLAC frame that is passed through libFLAC.  To pull out the raw frame instead, all you have to do is take libOggFLAC and modify it to return the frame instead of passing the frame down to libFLAC.

Josh

Problems muxing FLAC into matroska

Reply #2
Quote
- how about other lossless codecs like Wavpack or Optimfrog ? Do they have existing GPL libs that allow easy demuxing from their own framing ?

WavPack is 100% BSD, so there should be absolutely no licensing issues.

Problem is, the current version will surely not be suited for your needs. It doesn't search instantly, it chokes on each and every error, and there's no multichannel support.

David has already been working on WavPack4 that will address all these issues. I'm pertty confident he'll work on a good library interface as well, probably when beta stage is reached (it's supposed to go alpha soon and beta a few months later).



OptimFrog is completely closed. And I don't think it's a good option for your purposes, since it's too heavy on the CPU on both encoding and decoding.