1#[derive(Debug, Clone, PartialEq)]
6pub enum FfmpegEvent {
7 ParsedVersion(FfmpegVersion),
8 ParsedConfiguration(FfmpegConfiguration),
9 ParsedStreamMapping(String),
10 ParsedInput(FfmpegInput),
11 ParsedOutput(FfmpegOutput),
12 ParsedInputStream(Stream),
13 ParsedOutputStream(Stream),
14 ParsedDuration(FfmpegDuration),
15 Log(LogLevel, String),
16 LogEOF,
17 Error(String),
19 Progress(FfmpegProgress),
20 OutputFrame(OutputVideoFrame),
21 OutputChunk(Vec<u8>),
26 Done,
27}
28
29#[derive(Debug, Clone, PartialEq)]
31pub enum LogLevel {
32 Info,
33 Warning,
34 Error,
35 Fatal,
36 Unknown,
37}
38
39#[derive(Debug, Clone, PartialEq)]
40pub struct FfmpegInput {
41 pub index: u32,
42 pub duration: Option<f64>,
43 pub raw_log_message: String,
44}
45
46#[derive(Debug, Clone, PartialEq)]
47pub struct FfmpegDuration {
48 pub input_index: u32,
49 pub duration: f64,
50 pub raw_log_message: String,
51}
52
53#[derive(Debug, Clone, PartialEq)]
54pub struct FfmpegOutput {
55 pub to: String,
56 pub index: u32,
57 pub raw_log_message: String,
58}
59
60impl FfmpegOutput {
61 pub fn is_stdout(&self) -> bool {
63 ["pipe", "pipe:", "pipe:1"].contains(&self.to.as_str())
64 }
65}
66
67#[derive(Debug, Clone, PartialEq)]
69pub struct Stream {
70 pub format: String,
72 pub language: String,
74 pub parent_index: u32,
76 pub stream_index: u32,
78 pub raw_log_message: String,
80 pub type_specific_data: StreamTypeSpecificData,
82}
83
84impl Stream {
85 pub fn is_audio(&self) -> bool {
86 matches!(self.type_specific_data, StreamTypeSpecificData::Audio(_))
87 }
88 pub fn is_subtitle(&self) -> bool {
89 matches!(self.type_specific_data, StreamTypeSpecificData::Subtitle())
90 }
91 pub fn is_video(&self) -> bool {
92 matches!(self.type_specific_data, StreamTypeSpecificData::Video(_))
93 }
94 pub fn is_other(&self) -> bool {
95 matches!(self.type_specific_data, StreamTypeSpecificData::Other())
96 }
97
98 pub fn audio_data(&self) -> Option<&AudioStream> {
99 match &self.type_specific_data {
100 StreamTypeSpecificData::Audio(audio_stream) => Some(audio_stream),
101 _ => None,
102 }
103 }
104 pub fn video_data(&self) -> Option<&VideoStream> {
105 match &self.type_specific_data {
106 StreamTypeSpecificData::Video(video_stream) => Some(video_stream),
107 _ => None,
108 }
109 }
110}
111
112#[derive(Debug, Clone, PartialEq)]
116pub enum StreamTypeSpecificData {
117 Audio(AudioStream),
118 Video(VideoStream),
119 Subtitle(),
120 Other(),
121}
122
123#[derive(Debug, Clone, PartialEq)]
125pub struct AudioStream {
126 pub sample_rate: u32,
128 pub channels: String,
130}
131
132#[derive(Debug, Clone, PartialEq)]
134pub struct VideoStream {
135 pub pix_fmt: String,
137 pub width: u32,
139 pub height: u32,
141 pub fps: f32,
143}
144
145#[derive(Debug, Clone, PartialEq)]
146pub struct FfmpegVersion {
147 pub version: String,
148 pub raw_log_message: String,
149}
150
151#[derive(Debug, Clone, PartialEq)]
152pub struct FfmpegConfiguration {
153 pub configuration: Vec<String>,
154 pub raw_log_message: String,
155}
156
157#[derive(Debug, Clone, PartialEq)]
158pub struct FfmpegProgress {
159 pub frame: u32,
161
162 pub fps: f32,
164
165 pub q: f32,
167
168 pub size_kb: u32,
170
171 pub time: String,
173
174 pub bitrate_kbps: f32,
176
177 pub speed: f32,
182
183 pub raw_log_message: String,
185}
186
187#[derive(Clone, PartialEq)]
188pub struct OutputVideoFrame {
189 pub width: u32,
191 pub height: u32,
193 pub pix_fmt: String,
196 pub output_index: u32,
199 pub data: Vec<u8>,
202 pub frame_num: u32,
204 pub timestamp: f32,
206}
207
208impl std::fmt::Debug for OutputVideoFrame {
209 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
211 f.debug_struct("OutputVideoFrame")
212 .field("width", &self.width)
213 .field("height", &self.height)
214 .field("pix_fmt", &self.pix_fmt)
215 .field("output_index", &self.output_index)
216 .finish()
217 }
218}
219
220