PitchHut logo
A pure-Rust, WASM-compatible video codec for web applications.
Pitch

RIV offers a seamless solution for embedding pre-rendered video in Rust/WASM applications. With a focus on simplicity, it avoids complex C bindings or native dependencies. Featuring fast encoding and a self-contained design, RIV is ideal for developers needing video playback within their Rust environments.

Description

RIV (ReItero Video) is a pure Rust video codec designed specifically for web assembly (WASM) applications, offering a seamless and efficient way to embed pre-rendered video, such as cutscenes and trailers, within Rust/WASM environments. This repository eliminates the need for cumbersome Foreign Function Interfaces (FFI) to the WebDecoder API and avoids any native dependencies, making it an ideal choice for developers looking for a clean and straightforward video encoding solution.

Key Features

  • Pure Rust Implementation: With no reliance on C or system libraries, RIV streamlines the development process.
  • WASM Compatibility: Easily compiles to wasm32-unknown-unknown, ensuring smooth integration in web applications.
  • Efficient Encoding: Supports intraframe (I) and interframe (P) codecs with motion-compensated prediction, achieving approximately 80 fps on lower resolutions, and roughly on pair with the DivX codec in terms of compression efficiency.
  • Advanced Coding Techniques: Utilizes RANS entropy coding alongside DCT residual techniques for efficient compression.
  • Normative Specification: Comprehensive bitstream specification is available in SPEC.md, ensuring clarity and usability for developers.
  • Flexible Quality Settings: Users can adjust encoding quality to fit their needs, providing the ability to balance quality and bitrate effectively.

Usage Example

To utilize RIV in Rust projects, simply add the following dependencies to your Cargo.toml:

[dependencies]
reitero_encode = { git = "ssh://git@github.com/xhighway999/riv2.git", package = "reitero_encode" }
reitero_decode = { git = "ssh://git@github.com/xhighway999/riv2.git", package = "reitero_decode" }

Encoding Video

Here is a basic example of how to encode video frames using RIV:

use reitero_encode::{Encoder, EncoderConfig, Frame, VecWriter};

let config = EncoderConfig::new(1920, 1080, 30); // Configure width, height, and frame rate
let mut encoder = Encoder::new(config, VecWriter::new())?;

for (i, rgb_frame) in source_frames.iter().enumerate() {
    let timestamp_ms = (i as u64 * 1000) / 30;
    encoder.encode_frame(Frame::new(rgb_frame, 1920, 1080, timestamp_ms))?;
}

let riv_bytes: Vec<u8> = encoder.finish()?;

Decoding Video

To decode frames from an encoded RIV video:

use reitero_decode::Decoder;

let mut decoder = Decoder::new(my_reader)?;

while decoder.has_more_frames() {
    let frame = decoder.decode_frame()?;
    render(&frame.data, frame.width, frame.height);
}

Benchmark Performance

RIV demonstrates strong performance metrics, significantly outperforming VP9 in encoding speed while maintaining reasonable video quality. For example, on CIF resolution (352x288 at 30 fps), RIV achieved 1559 kbps with a PSNR of 33.95.

Benchmarks Summary

CodecQualityBitratePSNRSSIM
RIV95/901559 kbps33.950.923
VP9q=30630 kbps35.560.946

With a clear focus on simplicity and efficiency, RIV stands out as a robust solution for developers requiring video support in their Rust/WASM applications. For more extensive implementation details, refer to the full documentation within the repository.

0 comments

No comments yet.

Sign in to be the first to comment.