Skip to main content

MediaInfo

Struct MediaInfo 

Source
pub struct MediaInfo { /* private fields */ }
Expand description

Information about a media file.

This struct contains all metadata about a media container, including format information, duration, file size, and all contained streams.

§Construction

Use MediaInfo::builder() for fluent construction:

use ff_format::media::MediaInfo;
use std::time::Duration;

let info = MediaInfo::builder()
    .path("/path/to/video.mp4")
    .format("mp4")
    .duration(Duration::from_secs(120))
    .file_size(1_000_000)
    .build();

Implementations§

Source§

impl MediaInfo

Source

pub fn builder() -> MediaInfoBuilder

Creates a new builder for constructing MediaInfo.

§Examples
use ff_format::media::MediaInfo;
use std::time::Duration;

let info = MediaInfo::builder()
    .path("/path/to/video.mp4")
    .format("mp4")
    .duration(Duration::from_secs(120))
    .file_size(1_000_000)
    .build();
Source

pub fn path(&self) -> &Path

Returns the file path.

Source

pub fn format(&self) -> &str

Returns the container format name.

Source

pub fn format_long_name(&self) -> Option<&str>

Returns the long format name, if available.

Source

pub const fn duration(&self) -> Duration

Returns the total duration.

Source

pub const fn file_size(&self) -> u64

Returns the file size in bytes.

Source

pub const fn bitrate(&self) -> Option<u64>

Returns the overall bitrate in bits per second, if known.

Source

pub fn video_streams(&self) -> &[VideoStreamInfo]

Returns all video streams in the file.

Source

pub fn audio_streams(&self) -> &[AudioStreamInfo]

Returns all audio streams in the file.

Source

pub fn subtitle_streams(&self) -> &[SubtitleStreamInfo]

Returns all subtitle streams in the file.

Source

pub fn chapters(&self) -> &[ChapterInfo]

Returns all chapters in the file.

Source

pub fn has_chapters(&self) -> bool

Returns true if the file contains at least one chapter marker.

Source

pub fn chapter_count(&self) -> usize

Returns the number of chapters.

Source

pub fn metadata(&self) -> &HashMap<String, String>

Returns the file metadata.

Source

pub fn metadata_value(&self, key: &str) -> Option<&str>

Returns a specific metadata value by key.

Source

pub fn has_video(&self) -> bool

Returns true if the file contains at least one video stream.

Source

pub fn has_audio(&self) -> bool

Returns true if the file contains at least one audio stream.

Source

pub fn has_subtitles(&self) -> bool

Returns true if the file contains at least one subtitle stream.

Source

pub fn video_stream_count(&self) -> usize

Returns the number of video streams.

Source

pub fn audio_stream_count(&self) -> usize

Returns the number of audio streams.

Source

pub fn subtitle_stream_count(&self) -> usize

Returns the number of subtitle streams.

Source

pub fn stream_count(&self) -> usize

Returns the total number of streams (video + audio + subtitle).

Source

pub fn primary_video(&self) -> Option<&VideoStreamInfo>

Returns the primary video stream.

The primary video stream is the first video stream in the file. Returns None if there are no video streams.

Source

pub fn primary_audio(&self) -> Option<&AudioStreamInfo>

Returns the primary audio stream.

The primary audio stream is the first audio stream in the file. Returns None if there are no audio streams.

Source

pub fn video_stream(&self, index: usize) -> Option<&VideoStreamInfo>

Returns a video stream by index within the video streams list.

Source

pub fn audio_stream(&self, index: usize) -> Option<&AudioStreamInfo>

Returns an audio stream by index within the audio streams list.

Source

pub fn subtitle_stream(&self, index: usize) -> Option<&SubtitleStreamInfo>

Returns a subtitle stream by index within the subtitle streams list.

Source

pub fn resolution(&self) -> Option<(u32, u32)>

Returns the resolution of the primary video stream.

Returns None if there are no video streams.

Source

pub fn frame_rate(&self) -> Option<f64>

Returns the frame rate of the primary video stream.

Returns None if there are no video streams.

Source

pub fn sample_rate(&self) -> Option<u32>

Returns the sample rate of the primary audio stream.

Returns None if there are no audio streams.

Source

pub fn channels(&self) -> Option<u32>

Returns the channel count of the primary audio stream.

Returns None if there are no audio streams.

The type is u32 to match FFmpeg and professional audio APIs. For rodio or cpal (which require u16), cast with .map(|c| c as u16) — channel counts never exceed u16::MAX in practice.

Source

pub fn is_video_only(&self) -> bool

Returns true if this is a video-only file (no audio streams).

Source

pub fn is_audio_only(&self) -> bool

Returns true if this is an audio-only file (no video streams).

Source

pub fn file_name(&self) -> Option<&str>

Returns the file name (without directory path).

Source

pub fn extension(&self) -> Option<&str>

Returns the file extension.

Source

pub fn title(&self) -> Option<&str>

Returns the title from metadata.

This is a convenience method for accessing the “title” metadata key, which is commonly used by media containers to store the title of the content.

Source

pub fn artist(&self) -> Option<&str>

Returns the artist from metadata.

This is a convenience method for accessing the “artist” metadata key.

Source

pub fn album(&self) -> Option<&str>

Returns the album from metadata.

This is a convenience method for accessing the “album” metadata key.

Source

pub fn creation_time(&self) -> Option<&str>

Returns the creation time from metadata.

This is a convenience method for accessing the creation_time metadata key, which is commonly used by media containers to store when the file was created. The format is typically ISO 8601 (e.g., 2024-01-15T10:30:00.000000Z).

Source

pub fn date(&self) -> Option<&str>

Returns the date from metadata.

This is a convenience method for accessing the “date” metadata key.

Source

pub fn comment(&self) -> Option<&str>

Returns the comment from metadata.

This is a convenience method for accessing the “comment” metadata key.

Source

pub fn encoder(&self) -> Option<&str>

Returns the encoder from metadata.

This is a convenience method for accessing the “encoder” metadata key, which stores information about the software used to create the file.

Trait Implementations§

Source§

impl Clone for MediaInfo

Source§

fn clone(&self) -> MediaInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MediaInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for MediaInfo

Source§

fn default() -> MediaInfo

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.