7 releases (stable)

Uses new Rust 2024

2.2.0 Oct 9, 2025
2.0.0 Mar 12, 2025
2.0.0-alpha.1 Nov 19, 2024
1.1.2 Jun 12, 2024
0.1.0 Jul 21, 2015

#39 in Video

Download history 523/week @ 2025-07-25 375/week @ 2025-08-01 518/week @ 2025-08-08 466/week @ 2025-08-15 522/week @ 2025-08-22 528/week @ 2025-08-29 919/week @ 2025-09-05 1370/week @ 2025-09-12 664/week @ 2025-09-19 649/week @ 2025-09-26 603/week @ 2025-10-03 593/week @ 2025-10-10 561/week @ 2025-10-17 535/week @ 2025-10-24 643/week @ 2025-10-31 490/week @ 2025-11-07

2,344 downloads per month
Used in 5 crates

MPL-2.0 license

405KB
11K SLoC

C++ 10K SLoC // 0.1% comments Rust 1K SLoC // 0.0% comments

Rust idiomatic wrapper to libwebm MKV muxer.

Supports system-wide libwebm.

You'll also need libvpx to create VP8/VP9 frame data.


lib.rs:

A crate for muxing one or more video/audio streams into a WebM file.

Note that this crate is only for muxing media that has already been encoded with the appropriate codec. Consider a crate such as vpx if you need encoding as well.

Actual writing of muxed data is done through a mux::Writer, which lets you supply your own implementation. This makes it easy to support muxing to files, in-memory buffers, or whatever else you need. Once you have a mux::Writer, you create a mux::SegmentBuilder and add the tracks you need. Finally, you create a mux::Segment with that builder, to which you can add media frames.

In typical usage of this library, where you might mux to a WebM file, you would do:

use std::fs::File;
use webm::mux::{SegmentBuilder, SegmentMode, VideoCodecId, Writer};

let file = File::open("./my-cool-file.webm").unwrap();
let writer = Writer::new(file);

// Build a segment with a single video track
let builder = SegmentBuilder::new(writer).unwrap();
let builder = builder.set_mode(SegmentMode::Live).unwrap(); // Set live mode for streaming
let (builder, video_track) = builder.add_video_track(640, 480, VideoCodecId::VP8, None).unwrap();
let mut segment = builder.build();

// Add some video frames
let encoded_video_frame: &[u8] = &[]; // TODO: Your video data here
let timestamp_ns = 0;
let is_keyframe = true;
segment.add_frame(video_track, encoded_video_frame, timestamp_ns, is_keyframe).unwrap();
// TODO: More video frames

// Done writing frames, finish off the file
_ = segment.finalize(None).inspect_err(|_| eprintln!("Could not finalize WebM file"));

Dependencies

~235KB