This crate was built to ease parsing files encoded in a Matroska container, such as WebMs or MKVs.
[]
= "0.6.3"
Usage
The WebmIterator
type is an alias for ebml-iterable's TagIterator
using MatroskaSpec
as the generic type, and implements Rust's standard Iterator trait. This struct can be created with the new
function on any source that implements the standard Read trait. The iterator outputs MatroskaSpec
variants containing the tag data.
Note: The
with_capacity
method can be used to construct aWebmIterator
with a specified default buffer size. This is only useful as a microoptimization to memory management if you know the maximum tag size of the file you're reading.
The data in the tag can then be modified as desired (encryption, compression, etc.) and reencoded using the WebmWriter
type. WebmWriter
simply wraps ebml-iterable's TagWriter
. This struct can be created with the new
function on any source that implements the standard Write trait.
See the ebml-iterable docs for more information on iterating over ebml data if needed.
Matroska-specific types
This crate provides three additional structs for special matroska data tags:
Block
SimpleBlock
- [
Frame
] (not a tag itself, but used within Blocks & Simple Blocks)
Block
These properties are specific to the Block element as defined by Matroska. The Block
struct implements TryFrom<&MatroskaSpec>
and Into<MatroskaSpec>
to simplify coercion to and from regular variants.
SimpleBlock
These properties are specific to the SimpleBlock element as defined by Matroska. The SimpleBlock
struct also implements TryFrom<&MatroskaSpec>
and Into<MatroskaSpec>
to simplify coercion to and from regular variants.
Examples
This example reads a media file into memory and decodes it.
use File;
use WebmIterator;
This example does the same thing, but keeps track of the number of times each tag appears in the file.
use File;
use HashMap;
use WebmIterator;
use EbmlTag;
This example grabs the audio from a webm and stores the result in a new file. The logic in this example is rather advanced - an explanation follows the code.
use File;
use TryInto;
use ;
In the above example, we (1) build our iterator and writer based on local file paths and declare useful local variables, (2) iterate over the tags in the webm file, (3) identify any tracks that are not audio and store their numbers in the stripped_tracks
variable; if they are audio, we write the "TrackEntry" out, (4) only write block data for tracks that are audio, and (5) write all other tags to the output destination.
Notes
- Notice the second parameter passed into the
WebmIterator::new()
function. This parameter tells the decoder which "master" tags should be read asMaster::Full
variants rather than the standardMaster::Start
andMaster::End
variants. This greatly simplifies our iteration loop logic as we don't have to maintain an internal buffer for the "TrackEntry" tags that we are interested in processing.
State of this project
Parsing and writing complete files should both work. Streaming (using tags of unknown size) should now also supported as of version 0.4.0. If something is broken, please create an issue.
Any additional feature requests can also be submitted as an issue.