#[derive(Debug, Clone, PartialEq)]
pub enum FfmpegEvent {
ParsedVersion(FfmpegVersion),
ParsedConfiguration(FfmpegConfiguration),
ParsedStreamMapping(String),
ParsedInput(FfmpegInput),
ParsedOutput(FfmpegOutput),
ParsedInputStream(Stream),
ParsedOutputStream(Stream),
ParsedDuration(FfmpegDuration),
Log(LogLevel, String),
LogEOF,
Error(String),
Progress(FfmpegProgress),
OutputFrame(OutputVideoFrame),
OutputChunk(Vec<u8>),
Done,
}
#[derive(Debug, Clone, PartialEq)]
pub enum LogLevel {
Info,
Warning,
Error,
Fatal,
Unknown,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FfmpegInput {
pub index: u32,
pub duration: Option<f64>,
pub raw_log_message: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FfmpegDuration {
pub input_index: u32,
pub duration: f64,
pub raw_log_message: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FfmpegOutput {
pub to: String,
pub index: u32,
pub raw_log_message: String,
}
impl FfmpegOutput {
pub fn is_stdout(&self) -> bool {
["pipe", "pipe:", "pipe:1"].contains(&self.to.as_str())
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Stream {
pub format: String,
pub language: String,
pub parent_index: u32,
pub stream_index: u32,
pub raw_log_message: String,
pub type_specific_data: StreamTypeSpecificData,
}
impl Stream {
pub fn is_audio(&self) -> bool {
matches!(self.type_specific_data, StreamTypeSpecificData::Audio(_))
}
pub fn is_subtitle(&self) -> bool {
matches!(self.type_specific_data, StreamTypeSpecificData::Subtitle())
}
pub fn is_video(&self) -> bool {
matches!(self.type_specific_data, StreamTypeSpecificData::Video(_))
}
pub fn is_other(&self) -> bool {
matches!(self.type_specific_data, StreamTypeSpecificData::Other())
}
pub fn audio_data(&self) -> Option<&AudioStream> {
match &self.type_specific_data {
StreamTypeSpecificData::Audio(audio_stream) => Some(audio_stream),
_ => None,
}
}
pub fn video_data(&self) -> Option<&VideoStream> {
match &self.type_specific_data {
StreamTypeSpecificData::Video(video_stream) => Some(video_stream),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum StreamTypeSpecificData {
Audio(AudioStream),
Video(VideoStream),
Subtitle(),
Other(),
}
#[derive(Debug, Clone, PartialEq)]
pub struct AudioStream {
pub sample_rate: u32,
pub channels: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct VideoStream {
pub pix_fmt: String,
pub width: u32,
pub height: u32,
pub fps: f32,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FfmpegVersion {
pub version: String,
pub raw_log_message: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FfmpegConfiguration {
pub configuration: Vec<String>,
pub raw_log_message: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct FfmpegProgress {
pub frame: u32,
pub fps: f32,
pub q: f32,
pub size_kb: u32,
pub time: String,
pub bitrate_kbps: f32,
pub speed: f32,
pub raw_log_message: String,
}
#[derive(Clone, PartialEq)]
pub struct OutputVideoFrame {
pub width: u32,
pub height: u32,
pub pix_fmt: String,
pub output_index: u32,
pub data: Vec<u8>,
pub frame_num: u32,
pub timestamp: f32,
}
impl std::fmt::Debug for OutputVideoFrame {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("OutputVideoFrame")
.field("width", &self.width)
.field("height", &self.height)
.field("pix_fmt", &self.pix_fmt)
.field("output_index", &self.output_index)
.finish()
}
}