This crate was built to ease parsing files encoded in a Matroska container, such as WebMs or MKVs.
[]
= "0.1.0"
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 SpecTag
objects containing the type of Matroska tag and 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 EbmlTag
property 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 EbmlTag
, DataTag
, and DataTagType
if needed.
Matroska-specific types
This crate provides two additional subtypes of DataTagType
for ease of use:
Block
These properties are specific to the Block element as defined by Matroska. The Block
struct implements TryFrom<DataTagType>
and Into<DataTagType>
to simplify coercion to and from regular DataTagType::Binary
values.
SimpleBlock
These properties are specific to the SimpleBlock element as defined by Matroska. The SipleBlock
struct also implements TryFrom<DataTagType>
and Into<DataTagType>
to simplify coercion to and from regular DataTagType::Binary
values.
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;
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 track numbers that are not audio, store them in the stripped_tracks
variable, and prevent writing the "TrackEntry" out, (4) avoid writing any block data for any tracks that are not audio, and (5) write remaining tags to the output destination.
Notes
- Notice the second parameter passed into the
WebmIterator::new()
function. This parameter tells the decoder whichMaster
tags should be read asEbmlTag::FullTag
tags rather than the standardEbmlTag::StartTag
andEbmlTag::EndTag
variants. This greatly simplifies our iteration loop logic as we don't have to maintain an internal buffer for the "TrackEntry" tag that we are interested in processing.
State of this project
Parsing and writing complete files should both work. Streaming isn't supported yet, but may be an option in the future. If something is broken, please create an issue.
Any additional feature requests can also be submitted as an issue.