### Opening and Reading Matroska Files Source: https://docs.rs/matroska/latest/matroska?search= Examples demonstrating how to open a Matroska file and extract information like the title and duration. ```APIDOC ## Opening and Reading Matroska Files ### Description Examples demonstrating how to open a Matroska file and extract information like the title and duration. ### Functions Used - `open(path: &str)`: Opens a Matroska file on disk. - `get_from::<_, Info>(path: &str)`: Returns a single item from a Matroska file on disk, such as `Info`. - `get(item)`: Returns a single item from an open Matroska file. ### Example 1: Get Title ```rust let matroska = matroska::open("file.mkv").unwrap(); println!("title : {:?}", matroska.info.title); ``` ### Example 2: Get Duration ```rust use matroska::Info; if let Ok(Some(Info { duration, ..})) = matroska::get_from::<_, Info>("file.mkv") { println!("duration : {:?}", duration); } ``` ``` -------------------------------- ### Implement SimpleTag Builder Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initializes a SimpleTag and begins the element parsing loop. ```rust impl SimpleTag { fn new() -> SimpleTag { SimpleTag { name: String::new(), language: None, default: false, value: None, } } fn build_entry(elements: Vec) -> SimpleTag { let mut tag = SimpleTag::new(); for e in elements { ``` -------------------------------- ### GET Function for Matroska Parsing Source: https://docs.rs/matroska/latest/matroska/fn.get.html?search=std%3A%3Avec The `get` function retrieves a single parseable item from an open Matroska file. It supports various readable and seekable input types and returns a `Result` which can be `Ok` with an `Option` of the parsed output or an `Err` containing a `MatroskaError`. ```APIDOC ## GET /matroska ### Description Retrieves a single item from an open Matroska file, such as `Info`. ### Method GET ### Endpoint `/matroska` (Conceptual - this is a function call, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Function Signature ```rust pub fn get(file: R) -> Result, MatroskaError> where R: Read + Seek, P: Parseable, ``` ### Request Example ```rust use std::fs::File; use matroska::matroska::MatroskaError; use matroska::parse::Parseable; // Assuming 'file' is a File object opened for reading and seeking // and 'Info' is a type that implements Parseable // let result: Result, MatroskaError> = get(file); ``` ### Response #### Success Response (200 OK) - **Option** - An optional parsed output of type `P::Output` if an item was successfully parsed. #### Error Response - **MatroskaError** - An error encountered during the parsing process. #### Response Example ```json { "success": true, "data": { "type": "Info", "value": { ... } // Parsed Info data } } ``` ```json { "success": false, "error": { "code": "some_error_code", "message": "Error details" } } ``` ``` -------------------------------- ### Seektable Get Position Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Retrieves the file offset for a given ID from the Seektable. ```APIDOC ## Seektable Get Position ### Description Retrieves the file offset for a given ID from the Seektable. It checks if the ID exists and calculates the absolute offset. ### Method `get` ### Endpoint N/A (Method on Seektable struct) ### Parameters - **id** (u32) - The ID of the seek entry to retrieve. ### Request Example N/A ### Response #### Success Response (Ok) - **Option** - The file offset if the ID is found, otherwise None. #### Error Response - **MatroskaError::InvalidSeekHead** - If the calculated offset is invalid. #### Response Example ```json { "example": "Some(123456789)" } ``` ``` -------------------------------- ### Build Video Settings from Elements Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructs a `Video` struct by parsing a vector of `Element`s. Extracts pixel dimensions, display dimensions, interlacing, and gamma values. Initializes with default values. ```rust impl Video { fn new() -> Video { Video { pixel_width: 0, pixel_height: 0, display_width: None, display_height: None, interlaced: None, stereo: None, gamma: None, } } fn build(elements: Vec) -> Video { let mut video = Video::new(); for e in elements { match e { Element { id: ids::PIXELWIDTH, val: ElementType::UInt(width), .. } => { video.pixel_width = width; } Element { id: ids::PIXELHEIGHT, val: ElementType::UInt(height), .. } => { video.pixel_height = height; } Element { id: ids::DISPLAYWIDTH, val: ElementType::UInt(width), .. } => { video.display_width = Some(width); } Element { id: ids::DISPLAYHEIGHT, val: ElementType::UInt(height), .. } => video.display_height = Some(height), Element { id: ids::INTERLACED, val: ElementType::UInt(interlaced), .. } => { video.interlaced = match interlaced { 1 => Some(true), 2 => Some(false), _ => None, } } Element { id: ids::GAMMA, val: ElementType::Float(gamma), .. } => { ``` -------------------------------- ### Implement PartialEq for Video Source: https://docs.rs/matroska/latest/matroska/struct.Video.html?search=std%3A%3Avec Enables equality comparison between two Video instances. ```rust fn eq(&self, other: &Video) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### GET /matroska/get Source: https://docs.rs/matroska/latest/matroska/fn.get.html Retrieves a single parseable item from an open Matroska file. ```APIDOC ## GET /matroska/get ### Description Returns a single item from an open Matroska file, such as `Info`. ### Method GET ### Endpoint /matroska/get ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Output** (Parseable) - The parsed item from the Matroska file. #### Response Example ```json { "example": "Parsed Matroska data" } ``` ### Error Handling - **MatroskaError** - If an error occurs during parsing. ``` -------------------------------- ### Get Subtitle Tracks Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Returns an iterator over all tracks in the Matroska file that are of type 'subtitle'. ```APIDOC ## Get Subtitle Tracks ### Description Returns an iterator over all tracks in the Matroska file that are of type 'subtitle'. ### Method `subtitle_tracks` ### Endpoint N/A (Method on Matroska struct) ### Parameters None ### Request Example N/A ### Response #### Success Response (Ok) - **impl Iterator** - An iterator yielding references to subtitle tracks. #### Response Example ```json { "example": "Iterator over subtitle tracks" } ``` ``` -------------------------------- ### Track Building from Elements Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Demonstrates how a `Track` object is constructed by parsing a collection of `Element` objects, mapping specific element IDs to track properties. ```APIDOC ## Track Building from Elements ### Description This function constructs a `Track` object by iterating through a vector of `Element` objects and assigning their values to the corresponding track fields. It handles different `ElementType` variants and specific element IDs. ### Method `build_entry(elements: Vec) -> Track` ### Parameters - **elements** (Vec) - A vector of `Element` objects to parse. ### Logic Iterates through each `Element` in the provided vector. Based on the `id` and `val` of the `Element`, it updates the fields of a newly created `Track` object. Special handling is included for flags like `FLAGHEARINGIMPAIRED` to support both binary and unsigned integer representations as used by different tools. ``` -------------------------------- ### Get Audio Tracks Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Returns an iterator over all tracks in the Matroska file that are of type 'audio'. ```APIDOC ## Get Audio Tracks ### Description Returns an iterator over all tracks in the Matroska file that are of type 'audio'. ### Method `audio_tracks` ### Endpoint N/A (Method on Matroska struct) ### Parameters None ### Request Example N/A ### Response #### Success Response (Ok) - **impl Iterator** - An iterator yielding references to audio tracks. #### Response Example ```json { "example": "Iterator over audio tracks" } ``` ``` -------------------------------- ### Get Video Tracks Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Returns an iterator over all tracks in the Matroska file that are of type 'video'. ```APIDOC ## Get Video Tracks ### Description Returns an iterator over all tracks in the Matroska file that are of type 'video'. ### Method `video_tracks` ### Endpoint N/A (Method on Matroska struct) ### Parameters None ### Request Example N/A ### Response #### Success Response (Ok) - **impl Iterator** - An iterator yielding references to video tracks. #### Response Example ```json { "example": "Iterator over video tracks" } ``` ``` -------------------------------- ### Initialize Seektable Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new Seektable with a given file offset. The seek map is initially empty. ```rust fn new(offset: u64) -> Seektable { Seektable { offset, seek: BTreeMap::new(), } } ``` -------------------------------- ### CloneToUninit Experimental API Source: https://docs.rs/matroska/latest/matroska/enum.Settings.html An experimental, nightly-only API for performing copy-assignment from `self` to an uninitialized memory location. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Get Subtitle Tracks Source: https://docs.rs/matroska/latest/matroska/struct.Matroska.html Returns an iterator over all tracks in the Matroska file that have a type of 'subtitle'. ```rust pub fn subtitle_tracks(&self) -> impl Iterator ``` -------------------------------- ### Get Audio Tracks Source: https://docs.rs/matroska/latest/matroska/struct.Matroska.html Returns an iterator over all tracks in the Matroska file that have a type of 'audio'. ```rust pub fn audio_tracks(&self) -> impl Iterator ``` -------------------------------- ### Info Struct PartialEq Implementation Source: https://docs.rs/matroska/latest/matroska/struct.Info.html?search= Provides methods for comparing `Info` structs for equality. ```rust fn eq(&self, other: &Info) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Audio Struct Trait Implementations Source: https://docs.rs/matroska/latest/matroska/struct.Audio.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Details the trait implementations for the Audio struct, including Clone, Debug, PartialEq, and others. ```APIDOC ## Trait Implementations for Audio ### impl Clone for Audio - `fn clone(&self) -> Audio`: Returns a duplicate of the value. - `fn clone_from(&mut self, source: &Self)`: Performs copy-assignment from `source`. ### impl Debug for Audio - `fn fmt(&self, f: &mut Formatter<'_>) -> Result`: Formats the value using the given formatter. ### impl PartialEq for Audio - `fn eq(&self, other: &Audio) -> bool`: Tests for `self` and `other` values to be equal. - `fn ne(&self, other: &Rhs) -> bool`: Tests for `!=`. ### impl StructuralPartialEq for Audio ### Auto Trait Implementations - `Freeze` - `RefUnwindSafe` - `Send` - `Sync` - `Unpin` - `UnwindSafe` ### Blanket Implementations - `impl Any for T` - `impl Borrow for T` - `impl BorrowMut for T` - `impl CloneToUninit for T` - `impl From for T` - `impl Into for T` - `impl ToOwned for T` - `impl TryFrom for T` - `impl TryInto for T` ``` -------------------------------- ### Get Video Tracks Source: https://docs.rs/matroska/latest/matroska/struct.Matroska.html Returns an iterator over all tracks in the Matroska file that have a type of 'video'. ```rust pub fn video_tracks(&self) -> impl Iterator ``` -------------------------------- ### Define Settings and Video Structures Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html Defines the Settings enum and the Video struct for storing track-specific configuration. ```rust #[derive(Debug, Clone, PartialEq)] pub enum Settings { /// No settings (for non audio/video tracks) None, /// Video settings Video(Video), /// Audio settings Audio(Audio), } /// A video track's specifications #[derive(Debug, Clone, PartialEq)] pub struct Video { /// Width of encoded video frames in pixels pub pixel_width: u64, /// Height of encoded video frames in pixels pub pixel_height: u64, /// Width of video frames to display pub display_width: Option, /// Height of video frames to display pub display_height: Option, /// Whether video is interlaced pub interlaced: Option, /// Stereo video mode pub stereo: Option, /// Gamma pub gamma: Option, } ``` -------------------------------- ### get Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html Retrieves a single item (such as Info) from an open Matroska file stream. ```APIDOC ## get ### Description Reads an open Matroska file stream and attempts to locate and parse a specific element defined by the Parseable trait. ### Parameters - **file** (R: io::Read + io::Seek) - Required - The open file stream to read from. - **P** (Parseable) - Required - The type of element to parse. ### Response - **Result>** - Returns the parsed element if found, otherwise None. ``` -------------------------------- ### get Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search= Retrieves a single parseable item from an open Matroska file stream. ```APIDOC ## get ### Description Reads a Matroska file stream to find and parse a specific element (e.g., Info). It utilizes the SeekHead if available for efficient lookup, otherwise performs a sequential scan. ### Parameters - **file** (R: io::Read + io::Seek) - Required - The open file stream to read from. ### Response - **Result>** - Returns the parsed element if found, otherwise None. ``` -------------------------------- ### Implement Video Builder Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html Provides methods to initialize and build a Video struct from a list of Matroska elements. ```rust impl Video { fn new() -> Video { Video { pixel_width: 0, pixel_height: 0, display_width: None, display_height: None, interlaced: None, stereo: None, gamma: None, } } fn build(elements: Vec) -> Video { let mut video = Video::new(); for e in elements { match e { Element { id: ids::PIXELWIDTH, val: ElementType::UInt(width), .. } => { video.pixel_width = width; } Element { id: ids::PIXELHEIGHT, val: ElementType::UInt(height), .. } => { video.pixel_height = height; } Element { id: ids::DISPLAYWIDTH, val: ElementType::UInt(width), .. } => { video.display_width = Some(width); } Element { id: ids::DISPLAYHEIGHT, val: ElementType::UInt(height), .. } => video.display_height = Some(height), Element { id: ids::INTERLACED, val: ElementType::UInt(interlaced), .. } => { video.interlaced = match interlaced { 1 => Some(true), 2 => Some(false), _ => None, } } Element { id: ids::GAMMA, val: ElementType::Float(gamma), .. } => { video.gamma = Some(gamma); } _ => {} } } video } } ``` -------------------------------- ### Implement PartialEq for Audio Source: https://docs.rs/matroska/latest/matroska/struct.Audio.html Enables comparison of two Audio structs for equality. ```rust fn eq(&self, other: &Audio) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Function: get Source: https://docs.rs/matroska/latest/matroska/fn.get.html?search= Retrieves a single item from an open Matroska file, such as Info, based on the provided Parseable type. ```APIDOC ## GET get ### Description Returns a single item from an open Matroska file such as `Info`. ### Parameters #### Arguments - **file** (R: Read + Seek) - Required - The file handle to read from. - **P** (Parseable) - Required - The type of item to parse from the file. ### Response - **Result, MatroskaError>** - Returns the parsed item if found, or an error if the operation fails. ``` -------------------------------- ### fn open> Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html Opens a Matroska file from the specified path and returns a Matroska object. ```APIDOC ## fn open> ### Description Opens a Matroska file from the provided file path. It wraps the file in a BufReader and initializes the Matroska structure. ### Parameters #### Path Parameters - **path** (AsRef) - Required - The filesystem path to the Matroska file. ### Response - **Result** - Returns a Matroska object on success, or a MatroskaError::Io if an I/O error occurs. ``` -------------------------------- ### Function: get Source: https://docs.rs/matroska/latest/matroska/fn.get.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a single item from an open Matroska file, such as Info, based on the provided Parseable type. ```APIDOC ## get ### Description Returns a single item from an open Matroska file such as `Info`. ### Method Rust Function ### Parameters - **file** (R: Read + Seek) - Required - The file handle to read from. - **P** (Parseable) - Required - The type of item to parse from the file. ### Response - **Result, MatroskaError>** - Returns the parsed item if found, or an error if the operation fails. ``` -------------------------------- ### Track Parsing and Building Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Demonstrates how Matroska tracks are parsed from binary data and built into a structured format. ```APIDOC ## Track Parsing ### Description Parses a master element containing track entries and maps them to `Track` objects. ### Method `parse` ### Endpoint N/A (Internal parsing logic) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Vec) - `Vec`: A vector of parsed `Track` objects. #### Response Example None ## Track Building ### Description Builds a `Track` object from its sub-elements, determining its type and settings. ### Method `build_entry` (internal to `Track`) ### Endpoint N/A (Internal building logic) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (Track) - `Track`: A fully constructed `Track` object. #### Response Example None ``` -------------------------------- ### Get Matroska Element from File Path Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Opens a Matroska file from a given path and retrieves a specific parseable element. ```rust pub fn get_from(path: P) -> Result> where P: AsRef, R: Parseable, { std::fs::File::open(path) .map(std::io::BufReader::new) .map_err(MatroskaError::Io) .and_then(get::<_, R>) } ``` -------------------------------- ### Trait Implementations for Video Source: https://docs.rs/matroska/latest/matroska/struct.Video.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Details the trait implementations available for the Video struct, including Clone, Debug, PartialEq, and others. ```APIDOC ## Trait Implementations for Video ### impl Clone for Video - `fn clone(&self) -> Video`: Returns a duplicate of the value. - `fn clone_from(&mut self, source: &Self)`: Performs copy-assignment from `source`. ### impl Debug for Video - `fn fmt(&self, f: &mut Formatter<'_>) -> Result`: Formats the value using the given formatter. ### impl PartialEq for Video - `fn eq(&self, other: &Video) -> bool`: Tests for `self` and `other` values to be equal. - `fn ne(&self, other: &Rhs) -> bool`: Tests for `!=`. ### impl StructuralPartialEq for Video ### Auto Trait Implementations - `Freeze` - `RefUnwindSafe` - `Send` - `Sync` - `Unpin` - `UnwindSafe` ### Blanket Implementations - `impl Any for T` - `fn type_id(&self) -> TypeId`: Gets the `TypeId` of `self`. - `impl Borrow for T` - `fn borrow(&self) -> &T`: Immutably borrows from an owned value. - `impl BorrowMut for T` - `fn borrow_mut(&mut self) -> &mut T`: Mutably borrows from an owned value. - `impl CloneToUninit for T` (Nightly-only experimental API) - `unsafe fn clone_to_uninit(&self, dest: *mut u8)`: Performs copy-assignment from `self` to `dest`. - `impl From for T` - `fn from(t: T) -> T`: Returns the argument unchanged. - `impl Into for T` - `fn into(self) -> U`: Calls `U::from(self)`. - `impl ToOwned for T` - `type Owned = T` - `fn to_owned(&self) -> T`: Creates owned data from borrowed data, usually by cloning. - `fn clone_into(&self, target: &mut T)`: Uses borrowed data to replace owned data, usually by cloning. - `impl TryFrom for T` - `type Error = Infallible` - `fn try_from(value: U) -> Result>::Error>`: Performs the conversion. - `impl TryInto for T` - `type Error = >::Error` - `fn try_into(self) -> Result>::Error>`: Performs the conversion. ``` -------------------------------- ### Initialize a new Track Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Creates a default Track instance with initialized fields. ```rust impl Track { fn new() -> Track { Track { number: 0, uid: 0, tracktype: Tracktype::Unknown, enabled: true, default: true, forced: false, hearing_impaired: None, visual_impaired: None, text_descriptions: None, original: None, commentary: None, interlaced: true, default_duration: None, name: None, language: None, codec_id: String::new(), codec_private: None, codec_name: None, settings: Settings::None, } } ``` -------------------------------- ### Get Specific Matroska Element Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Retrieves a specific element (like Info) from a Matroska file without parsing the entire file. ```APIDOC ## GET /matroska/get_from ### Description Retrieves a specific element from a Matroska file. This is useful for accessing particular metadata without loading the entire file structure. ### Method GET ### Endpoint /matroska/get_from ### Parameters #### Path Parameters None #### Query Parameters - **element_type** (string) - Required - The type of element to retrieve (e.g., "Info", "Track"). - **file_path** (string) - Required - The path to the Matroska file. ### Request Example ```bash GET /matroska/get_from?element_type=Info&file_path=file.mkv ``` ### Response #### Success Response (200) - **ElementData** (any) - The data of the requested element. The structure depends on the `element_type` requested. #### Response Example ```json { "duration": "00:05:30.000" } ``` ``` -------------------------------- ### Seektable Get Position Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html Retrieves the file offset for a given ID from the seektable. Handles potential overflow when calculating the final offset. ```rust fn get(&self, id: u32) -> Result> { if let Some(position) = self.seek.get(&id) { if let Some(offset) = self.offset.checked_add(*position) { Ok(Some(offset)) } else { Err(MatroskaError::InvalidSeekHead { id }) } } else { Ok(None) } } ``` -------------------------------- ### From Trait Implementation Source: https://docs.rs/matroska/latest/matroska/struct.DateTime.html Enables conversion from DateTime to i64. ```APIDOC ### impl From for i64 #### fn from(DateTime: DateTime) -> Self Converts to this type from the input type. ``` -------------------------------- ### open

Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search= Opens a Matroska file from the disk for processing. ```APIDOC ## open

### Description Opens a Matroska file at the specified path and returns a Matroska object. ### Parameters - **path** (P: AsRef) - Required - The file system path to the Matroska file. ### Response - **Result** - Returns the initialized Matroska object. ``` -------------------------------- ### Get Seek Position Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves the calculated file offset for a given seek ID. Returns an error if the offset calculation overflows. ```rust #[inline] fn get(&self, id: u32) -> Result> { if let Some(position) = self.seek.get(&id) { if let Some(offset) = self.offset.checked_add(*position) { Ok(Some(offset)) } else { Err(MatroskaError::InvalidSeekHead { id }) } } else { Ok(None) } } ``` -------------------------------- ### Audio New Function Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructor for the Audio struct, initializing fields to default values. ```rust fn new() -> Audio { Audio { sample_rate: 0.0, channels: 0, bit_depth: None, } } ``` -------------------------------- ### Parseable Trait Implementations Source: https://docs.rs/matroska/latest/matroska/trait.Parseable.html Examples of the Parseable trait implemented for various Matroska elements, showing their specific ID and Output types. ```APIDOC ## impl Parseable for Attachment ### Associated Constants #### const ID: u32 = 423_732_329u32 ### Associated Types #### type Output = Vec ## impl Parseable for ChapterEdition ### Associated Constants #### const ID: u32 = 272_869_232u32 ### Associated Types #### type Output = Vec ## impl Parseable for Info ### Associated Constants #### const ID: u32 = 357_149_030u32 ### Associated Types #### type Output = Info ## impl Parseable for Tag ### Associated Constants #### const ID: u32 = 307_544_935u32 ### Associated Types #### type Output = Vec ## impl Parseable for Track ### Associated Constants #### const ID: u32 = 374_648_427u32 ### Associated Types #### type Output = Vec ``` -------------------------------- ### Build Chapter Edition Entry Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search= Initializes a ChapterEdition struct and populates its fields based on parsed elements. Handles edition UID and flags. ```rust fn build_entry(elements: Vec) -> ChapterEdition { let mut chapteredition = ChapterEdition::new(); for e in elements { match e { Element { id: ids::EDITIONUID, val: ElementType::UInt(uid), .. } => { chapteredition.uid = Some(uid); } Element { id: ids::EDITIONFLAGHIDDEN, val: ElementType::UInt(hidden), ``` -------------------------------- ### Get Matroska Item Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a specific item (such as Info) from the Matroska file. Note: This function is deprecated in favor of the matroska::get() function. ```APIDOC ## GET /matroska/get ### Description Retrieves a single item from the Matroska file, such as Info, Tracks, Attachments, Chapters, or Tags. ### Method GET ### Parameters #### Request Body - **file** (io::Read + io::Seek) - Required - The file stream to parse. - **P** (Parseable) - Required - The type of item to parse. ### Response #### Success Response (200) - **item** (Option) - The parsed item from the Matroska file. ``` -------------------------------- ### Info Struct New Function Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides a constructor for the `Info` struct, initializing all fields to their default values. ```rust impl Info { fn new() -> Info { Info { uid: None, prev_uid: None, next_uid: None, family_uids: Vec::new(), title: None, duration: None, date_utc: None, muxing_app: String::new(), writing_app: String::new(), } } } ``` -------------------------------- ### Get Single Item from Matroska File Source: https://docs.rs/matroska/latest/matroska/struct.Matroska.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Retrieves a single item, such as Info, from a Matroska file. Deprecated; use `matroska::get()` instead. ```rust pub fn get(file: R) -> Result, MatroskaError> where R: Read + Seek, P: Parseable, ``` -------------------------------- ### Get Single Item from Matroska File Source: https://docs.rs/matroska/latest/matroska/struct.Matroska.html Retrieves a single item, such as Info, from a Matroska file. Deprecated; use `matroska::get()` instead. ```rust pub fn get(file: R) -> Result, MatroskaError> where R: Read + Seek, P: Parseable, ``` -------------------------------- ### Implement TryFrom and TryInto for Fallible Conversions Source: https://docs.rs/matroska/latest/matroska/enum.Tracktype.html Provides fallible conversion methods between types. `TryFrom for T` attempts a conversion that might fail, returning a `Result`. `TryInto for T` is the reciprocal. ```rust type Error = Infallible ``` ```rust fn try_from(value: U) -> Result>::Error> ``` ```rust type Error = >::Error ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Build Chapter from Elements Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search= Provides a constructor and a builder method to initialize a Chapter instance from Matroska elements. ```rust impl Chapter { fn new() -> Chapter { Chapter { uid: 0, time_start: Duration::default(), time_end: None, hidden: false, enabled: false, segment_uid: None, segment_edition_uid: None, display: Vec::new(), } } fn build(elements: Vec) -> Chapter { let mut chapter = Chapter::new(); for e in elements { match e { Element { id: ids::CHAPTERUID, val: ElementType::UInt(uid), .. } => { chapter.uid = uid; } Element { id: ids::CHAPTERTIMESTART, val: ElementType::UInt(start), .. } => { chapter.time_start = Duration::from_nanos(start); } Element { id: ids::CHAPTERTIMEEND, val: ElementType::UInt(end), .. } => { chapter.time_end = Some(Duration::from_nanos(end)); } Element { id: ids::CHAPTERFLAGHIDDEN, val: ElementType::UInt(hidden), .. } => { chapter.hidden = hidden != 0; } Element { id: ids::CHAPTERFLAGENABLED, val: ElementType::UInt(enabled), .. } => { chapter.enabled = enabled != 0; } Element { id: ids::CHAPTERSEGMENTUID, val: ElementType::Binary(uid), .. } => { chapter.segment_uid = Some(uid); } Element { ``` -------------------------------- ### Get TypeId of a Generic Type Source: https://docs.rs/matroska/latest/matroska/struct.Track.html?search=u32+-%3E+bool Retrieves the unique TypeId for any given type T. This is part of the Any trait implementation, useful for runtime type identification. ```rust fn type_id(&self) -> TypeId; ``` -------------------------------- ### Error::cause Implementation for MatroskaError (Deprecated) Source: https://docs.rs/matroska/latest/matroska/enum.MatroskaError.html?search= Deprecated method for getting the underlying error cause. Use `Error::source` instead, which supports downcasting. ```rust fn cause(&self) -> Option<&dyn Error> { // Implementation details omitted for brevity } ``` -------------------------------- ### Implement Clone for Video Source: https://docs.rs/matroska/latest/matroska/struct.Video.html?search=std%3A%3Avec Provides methods for creating duplicates and performing copy-assignment for the Video struct. ```rust fn clone(&self) -> Video ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Get Specific Matroska Item Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Retrieves a single item from the Matroska file, such as Info. This function is deprecated and users should use the `matroska::get()` function instead. ```APIDOC ## Get Specific Matroska Item (Deprecated) ### Description Returns a single item from the Matroska file such as Info. This function is deprecated and users should use the `matroska::get()` function instead. ### Method `get` ### Endpoint N/A (Function call) ### Parameters - **file** (R: io::Read + io::Seek) - The input stream to read from. - **P** (Parseable) - The type of item to parse. ### Request Example N/A ### Response #### Success Response (Ok) - **Option** - An optional value of the parsed item type. #### Response Example ```json { "example": "Optional parsed item" } ``` ``` -------------------------------- ### Implement PartialEq for ChapterDisplay Source: https://docs.rs/matroska/latest/matroska/struct.ChapterDisplay.html Enables comparison of ChapterDisplay values for equality. ```rust fn eq(&self, other: &ChapterDisplay) -> bool ``` ```rust fn ne(&self, other: &Rhs) -> bool ``` -------------------------------- ### Settings Enum Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Defines the possible settings for audio or video tracks. ```APIDOC ## Settings Enum ### Description Represents the specific settings for audio or video tracks. ### Variants - **None**: No specific settings are defined. - **Video(VideoSettings)**: Settings specific to video tracks. - **Audio(AudioSettings)**: Settings specific to audio tracks. ``` -------------------------------- ### Retrieve Matroska item with get Source: https://docs.rs/matroska/latest/matroska/fn.get.html?search= Use this function to extract a specific parseable item from a Matroska file. The input must implement Read and Seek traits. ```rust pub fn get(file: R) -> Result, MatroskaError> where R: Read + Seek, P: Parseable, ``` -------------------------------- ### Error::description Implementation for MatroskaError (Deprecated) Source: https://docs.rs/matroska/latest/matroska/enum.MatroskaError.html?search= Deprecated method for getting a string description of the error. Prefer using the `Display` implementation or `to_string()` for error messages. ```rust fn description(&self) -> &str { // Implementation details omitted for brevity } ``` -------------------------------- ### Generic Blanket Implementations Source: https://docs.rs/matroska/latest/matroska/struct.ChapterEdition.html?search=u32+-%3E+bool Demonstrates blanket implementations for generic types, including Any, Borrow, BorrowMut, CloneToUninit, From, Into, ToOwned, TryFrom, and TryInto. ```rust fn type_id(&self) -> TypeId ``` ```rust fn borrow(&self) -> &T ``` ```rust fn borrow_mut(&mut self) -> &mut T ``` ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` ```rust fn from(t: T) -> T ``` ```rust fn into(self) -> U ``` ```rust type Owned = T; ``` ```rust fn to_owned(&self) -> T ``` ```rust fn clone_into(&self, target: &mut T) ``` ```rust type Error = Infallible; ``` ```rust fn try_from(value: U) -> Result>::Error> ``` ```rust type Error = >::Error; ``` ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Get Element from File Path Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Opens a Matroska file from a given path and retrieves a specific parseable element. This function abstracts the file opening and buffering process. ```APIDOC ## GET /api/matroska/get_from ### Description Retrieves a single item from a Matroska file on disk. ### Method GET ### Endpoint `/api/matroska/get_from` ### Parameters #### Query Parameters - **path** (P: AsRef) - Required - The path to the Matroska file. - **R** (Parseable) - Required - The type of element to parse. ### Response #### Success Response (200) - **Option** - An optional value containing the parsed element, or None if not found. #### Response Example ```json { "example": "Some(ParsedElement)" } ``` ``` -------------------------------- ### Info Implementation and Parsing Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Provides the constructor and Parseable implementation for the Info struct. ```rust impl Info { fn new() -> Info { Info { uid: None, prev_uid: None, next_uid: None, family_uids: Vec::new(), title: None, duration: None, date_utc: None, muxing_app: String::new(), writing_app: String::new(), } } } impl Parseable for Info { type Output = Info; const ID: u32 = ids::INFO; fn parse(r: &mut R, size: u64) -> Result { let mut info = Info::new(); let mut timecode_scale = 1000000; let mut duration = None; for e in Element::parse_master(r, size, Some(ids::INFO))? { match e { Element { id: ids::SEGMENTUID, val: ElementType::Binary(uid), .. } => { info.uid = Some(uid); } Element { id: ids::PREVUID, val: ElementType::Binary(uid), .. } => { info.prev_uid = Some(uid); } Element { id: ids::NEXTUID, val: ElementType::Binary(uid), .. } => { info.next_uid = Some(uid); } Element { id: ids::SEGMENTFAMILY, val: ElementType::Binary(uid), .. } => { info.family_uids.push(uid); } Element { id: ids::TITLE, val: ElementType::UTF8(title), .. } => { info.title = Some(title); } Element { id: ids::TIMECODESCALE, val: ElementType::UInt(scale), .. } => { timecode_scale = scale; } Element { id: ids::DURATION, val: ElementType::Float(d), .. } => duration = Some(d), Element { id: ids::DATEUTC, val: ElementType::Date(date), .. } => info.date_utc = Some(date), Element { id: ids::MUXINGAPP, val: ElementType::UTF8(app), .. } => { info.muxing_app = app; } Element { id: ids::WRITINGAPP, val: ElementType::UTF8(app), .. } => { info.writing_app = app; } _ => {} } } if let Some(d) = duration { info.duration = Some(Duration::from_nanos((d * timecode_scale as f64) as u64)) } Ok(info) } } ``` -------------------------------- ### Deprecated Get Function for Matroska Items Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E A deprecated function to retrieve a single parsable item from a Matroska file. It is recommended to use the `matroska::get()` function instead. ```rust /// Returns a single item from the Matroska file such as Info #[deprecated(since = "0.21.0", note = "use matroska::get() function instead")] pub fn get(file: R) -> Result> where R: io::Read + io::Seek, P: Parseable, { get::(file) } ``` -------------------------------- ### Implement Clone for Audio Source: https://docs.rs/matroska/latest/matroska/struct.Audio.html Provides functionality to create a duplicate of an Audio struct instance. ```rust fn clone(&self) -> Audio ``` ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Get Element from Reader Source: https://docs.rs/matroska/latest/src/matroska/lib.rs.html?search=u32+-%3E+bool Retrieves a specific parseable element from an open Matroska file reader. It handles seeking to the correct position based on the file structure, including the use of a SeekHead if available. ```APIDOC ## GET /api/matroska/get ### Description Retrieves a single item from an open Matroska file reader. ### Method GET ### Endpoint `/api/matroska/get` ### Parameters #### Query Parameters - **R** (io::Read + io::Seek) - Required - The reader for the Matroska file. - **P** (Parseable) - Required - The type of element to parse. ### Response #### Success Response (200) - **Option** - An optional value containing the parsed element, or None if not found. #### Response Example ```json { "example": "Some(ParsedElement)" } ``` ``` -------------------------------- ### Opening and Reading Matroska File Info Source: https://docs.rs/matroska/latest/matroska/index.html?search=u32+-%3E+bool Demonstrates how to open a Matroska file and access its title information. ```APIDOC ## Rust Example: Accessing Matroska File Title ### Description This example shows how to open a Matroska file using the `matroska::open` function and then access the `title` field from the `info` struct. ### Method `matroska::open` followed by direct struct field access. ### Endpoint N/A (Local file operation) ### Parameters #### Path Parameters - **file.mkv** (string) - Required - The path to the Matroska file. ### Request Example ```rust let matroska = matroska::open("file.mkv").unwrap(); println!("title : {:?}", matroska.info.title); ``` ### Response #### Success Response (200) Prints the title of the Matroska file to the console. #### Response Example ``` title : Some("My Video Title") ``` ``` -------------------------------- ### Function open Source: https://docs.rs/matroska/latest/matroska/fn.open.html?search= Opens a Matroska file from the specified path. ```APIDOC ## open ### Description Opens Matroska file on disk. ### Method `pub fn open>(path: P) -> Result` ### Endpoint N/A (This is a Rust function, not an API endpoint) ### Parameters #### Path Parameters - **path** (P: AsRef) - Required - The path to the Matroska file. ### Response #### Success Response - **Matroska** - Represents the opened Matroska file. #### Error Response - **MatroskaError** - An error that occurred during file opening. ``` -------------------------------- ### Get Single Item from Matroska File Source: https://docs.rs/matroska/latest/matroska/fn.get_from.html?search= Use this function to retrieve a specific item, like `Info`, from a Matroska file. It requires a path to the file and a type that implements `Parseable` for the item to be returned. ```rust pub fn get_from(path: P) -> Result, MatroskaError> where P: AsRef, R: Parseable, ``` -------------------------------- ### Get Single Item from Matroska File Source: https://docs.rs/matroska/latest/matroska/fn.get.html Use this function to retrieve a single item, such as `Info`, from an open Matroska file. Requires the file to implement `Read` and `Seek`, and the item type `P` to implement `Parseable`. ```rust pub fn get(file: R) -> Result, MatroskaError> where R: Read + Seek, P: Parseable, ``` -------------------------------- ### Info Struct Clone Implementation Source: https://docs.rs/matroska/latest/matroska/struct.Info.html?search= Provides methods for cloning and copying the `Info` struct. ```rust fn clone(&self) -> Info ``` ```rust fn clone_from(&mut self, source: &Self) ```