implement video stream iterating
This commit is contained in:
parent
2e6edffcb7
commit
42fbf46fd7
2 changed files with 27 additions and 5 deletions
|
|
@ -140,7 +140,13 @@ enum Command {
|
|||
use crate::dl::ffprobe::FFProbe;
|
||||
|
||||
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
|
||||
dbg!(FFProbe::probe("/home/mykola/Videos/test-video").await);
|
||||
if let Ok(probe) = FFProbe::probe("/home/mykola/Videos/test-video").await {
|
||||
if let Some(vs) = probe.get_video_stream() {
|
||||
dbg!(vs.get_video_resolution());
|
||||
}
|
||||
} else {
|
||||
dbg!("failed");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,20 @@ pub struct FFProbeStream {
|
|||
pub duration: f64
|
||||
}
|
||||
|
||||
impl FFProbeStream {
|
||||
pub fn is_video_stream(&self) -> bool {
|
||||
self.width.is_some() && self.height.is_some()
|
||||
}
|
||||
|
||||
pub fn get_video_resolution(&self) -> Option<(u32, u32)> {
|
||||
if self.is_video_stream() {
|
||||
return Some((self.width.unwrap(), self.height.unwrap()))
|
||||
}
|
||||
|
||||
return None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct FFProbeOutput {
|
||||
pub streams: Vec<FFProbeStream>
|
||||
|
|
@ -32,11 +46,13 @@ pub struct FFProbeOutput {
|
|||
|
||||
impl FFProbeOutput {
|
||||
pub fn parse(json: &[u8]) -> Result<FFProbeOutput, serde_json::Error> {
|
||||
let output: Result<FFProbeOutput, _> = serde_json::from_slice(json);
|
||||
dbg!(output);
|
||||
let output: FFProbeOutput = serde_json::from_slice(json)?;
|
||||
|
||||
todo!();
|
||||
//Ok(output)
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
pub fn get_video_stream(&self) -> Option<&FFProbeStream> {
|
||||
self.streams.iter().find(|&s| s.is_video_stream())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue