ruuda / claxon

A FLAC decoder in Rust
Apache License 2.0
285 stars 28 forks source link

Support alternative containers #5

Open est31 opened 7 years ago

est31 commented 7 years ago

Flac doesn't have to be inside its own custom container, it can also be encapsulated inside ogg or inside the mp4 container. It would be cool if this crate supported those use cases, maybe through optional cargo features.

My lewton crate is organized in a very generic fashion: its main function only takes a byte slice and treats that as one packet, regardless of the actual container format. The entire crate knows nothing about the container format, except for the inside_ogg module. Having such a setup for the claxon crate would be really cool.

ruuda commented 7 years ago

Claxon implements the FLAC spec which describes bit by bit what the stream should look like, and the spec makes no mention of embedding. So any container format that embeds FLAC would have to specify how it does so. If it embeds the streaminfo and frames without modification, then adding support for reading those would not be very hard. Actually, the FrameReader is already public (but some of its type parameters are not).

Do you have any references for container formats that embed FLAC? I was able to find the ogg mapping and it looks like that one indeed embeds frames directly.

est31 commented 7 years ago

The mp4 mapping should be described here: https://github.com/xiph/flac/blob/master/doc/isoflac.txt For mp4 there is the mp4parse crate which should support flac (I hope?): https://github.com/mozilla/mp4parse-rust

For the ogg mapping, my ogg crate should contain all relevant things: https://github.com/rustaudio/ogg If you need something, please write!

I don't know about embeddings in other formats. The mp4 mapping spec only has a link to the ogg mapping, not to other mappings.

ruuda commented 7 years ago

I have added an example that shows how to read flac from an mp4 container using mp4parse. All the building blocks were there, but I had to expose a few things to get it working.

Reading from ogg will be a little bit more involved, because the header packet has a few fields before the streaminfo. It is only 12 bytes, mostly constants. Does Vorbis have some kind of identifying mark in the first packet too? Perhaps this is something that the ogg crate could recognize and parse, similar to how the mp4parse crate is aware of flac metadata blocks?

est31 commented 7 years ago

Does Vorbis have some kind of identifying mark in the first packet too?

Yes, vorbis has an identifying mark, but its being recognized in lewton, not by the ogg crate.

Some containers transmit info about the kind of the stream within their own custom metatadata, other container formats like ogg don't do this. For ogg, everything is just opaque data.

All the building blocks were there, but I had to expose a few things to get it working.

Really cool!

ruuda commented 7 years ago

I added an ogg example too now!

There are still a few rough edges in the Claxon API; I plan to implement a few more things to make reading from external container a bit nicer (the to dos in the examples). I’ll keep this issue open until then.