Skip to main content

Module media

Module media 

Source
Expand description

Media container information.

This module provides the MediaInfo struct for representing metadata about a media file as a whole, including all its video and audio streams.

§Examples

use ff_format::media::{MediaInfo, MediaInfoBuilder};
use ff_format::stream::{VideoStreamInfo, AudioStreamInfo};
use ff_format::{PixelFormat, SampleFormat, Rational};
use ff_format::codec::{VideoCodec, AudioCodec};
use std::time::Duration;
use std::path::PathBuf;

// Create video stream info
let video = VideoStreamInfo::builder()
    .index(0)
    .codec(VideoCodec::H264)
    .width(1920)
    .height(1080)
    .frame_rate(Rational::new(30, 1))
    .pixel_format(PixelFormat::Yuv420p)
    .build();

// Create audio stream info
let audio = AudioStreamInfo::builder()
    .index(1)
    .codec(AudioCodec::Aac)
    .sample_rate(48000)
    .channels(2)
    .sample_format(SampleFormat::F32)
    .build();

// Create media info
let media = MediaInfo::builder()
    .path("/path/to/video.mp4")
    .format("mp4")
    .format_long_name("QuickTime / MOV")
    .duration(Duration::from_secs(120))
    .file_size(1_000_000)
    .bitrate(8_000_000)
    .video_stream(video)
    .audio_stream(audio)
    .metadata("title", "Sample Video")
    .metadata("artist", "Test Artist")
    .build();

assert!(media.has_video());
assert!(media.has_audio());
assert_eq!(media.resolution(), Some((1920, 1080)));

Structs§

MediaInfo
Information about a media file.
MediaInfoBuilder
Builder for constructing MediaInfo.