Skip to main content

Crate libfreemkv

Crate libfreemkv 

Source
Expand description

libfreemkv – Open source optical drive library for 4K UHD / Blu-ray / DVD.

Handles drive access, disc structure parsing, AACS decryption, and raw sector reading. 206 bundled drive profiles. No external files needed.

§Quick Start

use libfreemkv::{Drive, Disc, ScanOptions, find_drive};

let mut drive = find_drive().expect("no optical drive found");
drive.wait_ready().unwrap();
drive.init().unwrap();
let disc = Disc::scan(&mut drive, &ScanOptions::default()).unwrap();

for title in &disc.titles {
    println!("{} -- {} streams", title.duration_display(), title.streams.len());
}

// Stream via PES pipeline
let opts = libfreemkv::InputOptions::default();
let mut input = libfreemkv::input("disc://", &opts).unwrap();
let title = input.info().clone();
let mut output = libfreemkv::output("mkv://Movie.mkv", &title).unwrap();
while let Ok(Some(frame)) = input.read() {
    output.write(&frame).unwrap();
}
output.finish().unwrap();

§Architecture

Drive           -- open, identify, unlock, read sectors
  ├── ScsiTransport    -- SG_IO (Linux), IOKit (macOS)
  ├── DriveProfile     -- per-drive unlock parameters (206 bundled)
  ├── DriveId          -- INQUIRY + GET_CONFIG identification
  └── Platform
      └── Mt1959       -- MediaTek unlock/read (Renesas planned)

Disc                   -- scan titles, streams, AACS state
  ├── UDF reader       -- Blu-ray UDF 2.50 with metadata partitions
  ├── MPLS parser      -- playlists → titles + clips + STN streams
  ├── CLPI parser      -- clip info → EP map → sector extents
  ├── JAR parser       -- BD-J audio track labels
  └── AACS             -- encryption: key resolution + content decrypt
      ├── aacs         -- KEYDB, VUK, MKB, unit decrypt
      └── handshake    -- SCSI auth, ECDH, bus key

§AACS Encryption

Disc scanning automatically detects and handles AACS encryption. If a KEYDB.cfg is available (via ScanOptions or standard paths), the library resolves keys and decrypts content transparently.

Supports AACS 1.0 (Blu-ray) and AACS 2.0 (UHD, with fallback).

§Error Codes

All errors are structured with numeric codes. No user-facing English text – applications format their own messages.

RangeCategory
E1xxxDevice errors (not found, permission)
E2xxxProfile errors (unsupported drive)
E3xxxUnlock errors (failed, signature)
E4xxxSCSI errors (command failed, timeout)
E5xxxI/O errors
E6xxxDisc format errors
E7xxxAACS errors

Re-exports§

pub use drive::capture::capture_drive_data;
pub use drive::capture::mask_bytes;
pub use drive::capture::mask_string;
pub use drive::capture::CapturedFeature;
pub use drive::capture::DriveCapture;
pub use drive::find_drive;
pub use drive::find_drives;
pub use drive::Drive;
pub use drive::DriveStatus;
pub use error::Error;
pub use error::Result;
pub use event::Event;
pub use event::EventKind;
pub use profile::DriveProfile;
pub use decrypt::decrypt_sectors;
pub use decrypt::DecryptKeys;
pub use disc::AacsState;
pub use disc::AudioChannels;
pub use disc::AudioStream;
pub use disc::Clip;
pub use disc::Codec;
pub use disc::ColorSpace;
pub use disc::ContentFormat;
pub use disc::Disc;
pub use disc::DiscFormat;
pub use disc::DiscTitle;
pub use disc::Extent;
pub use disc::FrameRate;
pub use disc::HdrFormat;
pub use disc::KeySource;
pub use disc::Resolution;
pub use disc::SampleRate;
pub use disc::ScanOptions;
pub use disc::Stream;
pub use disc::SubtitleStream;
pub use disc::VideoStream;
pub use mux::DiscStream;
pub use mux::M2tsStream;
pub use mux::MkvStream;
pub use mux::NetworkStream;
pub use mux::NullStream;
pub use mux::StdioStream;
pub use mux::input;
pub use mux::output;
pub use mux::parse_url;
pub use mux::InputOptions;
pub use mux::StreamUrl;
pub use scsi::ScsiTransport;
pub use sector::SectorReader;

Modules§

aacs
AACS decryption — Volume Unique Key lookup and title key derivation.
css
CSS (Content Scramble System) — DVD disc encryption.
decrypt
Decrypt-on-read layer.
disc
Disc structure – scan titles, streams, and sector ranges from a Blu-ray disc.
drive
Drive session — open, identify, and read from optical drives.
error
Error types for libfreemkv.
event
Event system for progress and status reporting.
keydb
KEYDB.cfg updater — HTTP GET, unzip, verify, save.
mux
Stream-based I/O pipeline.
pes
Stream — read PES frames in, write PES frames out.
profile
Drive profile loading and matching.
scsi
SCSI/MMC command interface.
sector
SectorReader — trait for reading 2048-byte disc sectors.

Structs§

DriveId
Drive identity from standard SCSI commands.
UdfFs
A UDF filesystem parsed from disc.

Enums§

DriveSpeed
Common optical drive speeds with KB/s values for SET_CD_SPEED.

Functions§

read_filesystem
Read the UDF filesystem from a Blu-ray disc.