1#![warn(missing_docs)]
52#![warn(clippy::all)]
53#![warn(clippy::pedantic)]
54
55pub mod channel;
57pub mod chapter;
58pub mod codec;
59pub mod color;
60pub mod container;
61pub mod error;
62pub mod frame;
63pub mod hdr;
64pub mod media;
65pub mod network;
66pub mod pixel;
67pub mod sample;
68pub mod stream;
69pub mod time;
70
71pub use channel::ChannelLayout;
72pub use chapter::{ChapterInfo, ChapterInfoBuilder};
73pub use codec::{AudioCodec, SubtitleCodec, VideoCodec};
74pub use color::{ColorPrimaries, ColorRange, ColorSpace, ColorTransfer};
75pub use container::{ContainerInfo, ContainerInfoBuilder};
76pub use error::{FormatError, FrameError};
77pub use ff_common::PooledBuffer;
78pub use frame::{AudioFrame, VideoFrame};
79pub use hdr::{Hdr10Metadata, MasteringDisplay};
80pub use media::{MediaInfo, MediaInfoBuilder};
81pub use network::NetworkOptions;
82pub use pixel::PixelFormat;
83pub use sample::SampleFormat;
84pub use stream::{
85 AudioStreamInfo, AudioStreamInfoBuilder, SubtitleStreamInfo, SubtitleStreamInfoBuilder,
86 VideoStreamInfo, VideoStreamInfoBuilder,
87};
88pub use time::{Rational, Timestamp};
89
90pub mod prelude {
98 pub use crate::{
99 AudioCodec, AudioFrame, AudioStreamInfo, ChannelLayout, ChapterInfo, ColorPrimaries,
100 ColorRange, ColorSpace, FormatError, FrameError, MediaInfo, NetworkOptions, PixelFormat,
101 PooledBuffer, Rational, SampleFormat, Timestamp, VideoCodec, VideoFrame, VideoStreamInfo,
102 };
103}
104
105#[cfg(test)]
106mod tests {
107 use super::*;
108
109 #[test]
110 fn test_prelude_exports() {
111 let _pixel: PixelFormat = PixelFormat::default();
113 let _sample: SampleFormat = SampleFormat::default();
114 let _rational: Rational = Rational::default();
115 let _timestamp: Timestamp = Timestamp::default();
116 let _video_frame: VideoFrame = VideoFrame::default();
117 let _audio_frame: AudioFrame = AudioFrame::default();
118
119 let _color_space: ColorSpace = ColorSpace::default();
121 let _color_range: ColorRange = ColorRange::default();
122 let _color_primaries: ColorPrimaries = ColorPrimaries::default();
123 let _video_codec: VideoCodec = VideoCodec::default();
124 let _audio_codec: AudioCodec = AudioCodec::default();
125 let _channel_layout: ChannelLayout = ChannelLayout::default();
126 let _video_stream: VideoStreamInfo = VideoStreamInfo::default();
127 let _audio_stream: AudioStreamInfo = AudioStreamInfo::default();
128 let _media_info: MediaInfo = MediaInfo::default();
129 let _network_opts: NetworkOptions = NetworkOptions::default();
130 }
131
132 #[test]
133 fn test_stream_info_builder() {
134 let video = VideoStreamInfo::builder()
136 .index(0)
137 .codec(VideoCodec::H264)
138 .width(1920)
139 .height(1080)
140 .frame_rate(Rational::new(30, 1))
141 .pixel_format(PixelFormat::Yuv420p)
142 .color_space(ColorSpace::Bt709)
143 .build();
144
145 assert_eq!(video.width(), 1920);
146 assert_eq!(video.height(), 1080);
147 assert_eq!(video.codec(), VideoCodec::H264);
148 assert_eq!(video.color_space(), ColorSpace::Bt709);
149
150 let audio = AudioStreamInfo::builder()
152 .index(1)
153 .codec(AudioCodec::Aac)
154 .sample_rate(48000)
155 .channels(2)
156 .sample_format(SampleFormat::F32)
157 .build();
158
159 assert_eq!(audio.sample_rate(), 48000);
160 assert_eq!(audio.channels(), 2);
161 assert_eq!(audio.codec(), AudioCodec::Aac);
162 assert_eq!(audio.channel_layout(), ChannelLayout::Stereo);
163 }
164
165 #[test]
166 fn test_media_info_builder() {
167 use std::time::Duration;
168
169 let video = VideoStreamInfo::builder()
171 .index(0)
172 .codec(VideoCodec::H264)
173 .width(1920)
174 .height(1080)
175 .frame_rate(Rational::new(30, 1))
176 .build();
177
178 let audio = AudioStreamInfo::builder()
179 .index(1)
180 .codec(AudioCodec::Aac)
181 .sample_rate(48000)
182 .channels(2)
183 .build();
184
185 let media = MediaInfo::builder()
187 .path("/path/to/video.mp4")
188 .format("mp4")
189 .format_long_name("QuickTime / MOV")
190 .duration(Duration::from_secs(120))
191 .file_size(100_000_000)
192 .bitrate(8_000_000)
193 .video_stream(video)
194 .audio_stream(audio)
195 .metadata("title", "Test Video")
196 .build();
197
198 assert!(media.has_video());
199 assert!(media.has_audio());
200 assert_eq!(media.resolution(), Some((1920, 1080)));
201 assert!((media.frame_rate().unwrap() - 30.0).abs() < 0.001);
202 assert_eq!(media.sample_rate(), Some(48000));
203 assert_eq!(media.channels(), Some(2));
204 assert_eq!(media.format(), "mp4");
205 assert_eq!(media.format_long_name(), Some("QuickTime / MOV"));
206 assert_eq!(media.metadata_value("title"), Some("Test Video"));
207 }
208}