begin working on ffprobe
This commit is contained in:
parent
0bf6c1b63e
commit
cccff3edc2
3 changed files with 81 additions and 2 deletions
|
|
@ -15,8 +15,14 @@ async fn bot_download(bot: Bot, msg: Message, url: String) -> HandlerResult {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bot.send_video(msg.chat.id, InputFile::file(&output.path))
|
// query media info with
|
||||||
.await?;
|
// ffprobe -v quiet -print_format json -show_streams -select_streams v:0 input.mp4
|
||||||
|
|
||||||
|
let mut video = bot.send_video(msg.chat.id, InputFile::file(&output.path));
|
||||||
|
// set width, height and so on
|
||||||
|
|
||||||
|
video.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use self::tmpfile::{TmpFile, TmpFileError};
|
||||||
use self::yt_dlp::{YtDlp, YtDlpError, YtDlpInfo};
|
use self::yt_dlp::{YtDlp, YtDlpError, YtDlpInfo};
|
||||||
|
|
||||||
pub mod ffmpeg;
|
pub mod ffmpeg;
|
||||||
|
pub mod ffprobe;
|
||||||
pub mod spawn;
|
pub mod spawn;
|
||||||
mod tmpfile;
|
mod tmpfile;
|
||||||
pub mod yt_dlp;
|
pub mod yt_dlp;
|
||||||
|
|
|
||||||
72
src/dl/ffprobe.rs
Normal file
72
src/dl/ffprobe.rs
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
use super::spawn::{spawn, SpawnError};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct FFProbeStream {
|
||||||
|
pub index: u32,
|
||||||
|
pub codec_name: String,
|
||||||
|
pub width: u32,
|
||||||
|
pub height: u32,
|
||||||
|
pub coded_width: u32,
|
||||||
|
pub coded_height: u32,
|
||||||
|
pub time_base: String,
|
||||||
|
pub duration_ts: u64,
|
||||||
|
pub duration: f64
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct FFProbeOutput {
|
||||||
|
pub streams: Vec<FFProbeStream>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FFProbeOutput {
|
||||||
|
pub fn parse(json: &[u8]) -> Result<FFProbeOutput, serde_json::Error> {
|
||||||
|
let output: FFProbeOutput = serde_json::from_slice(json)?;
|
||||||
|
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum FFProbeError {
|
||||||
|
SpawnError(SpawnError),
|
||||||
|
JsonError
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SpawnError> for FFProbeError {
|
||||||
|
fn from(value: SpawnError) -> Self {
|
||||||
|
Self::SpawnError(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<serde_json::Error> for FFProbeError {
|
||||||
|
fn from(value: serde_json::Error) -> Self {
|
||||||
|
Self::JsonError
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for FFProbeError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
use FFProbeError as FFPE;
|
||||||
|
match (self) {
|
||||||
|
FFPE::SpawnError(e) => write!(f, "{}", e),
|
||||||
|
FFPE::JsonError => write!(f, "ffprobe json error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FFProbe {}
|
||||||
|
impl FFProbe {
|
||||||
|
pub async fn probe(input_path: &str) -> Result<FFProbeOutput, FFProbeError> {
|
||||||
|
let output = spawn("ffprobe", &[
|
||||||
|
"-v", "quiet",
|
||||||
|
"-print_format", "json",
|
||||||
|
"-show_streams",
|
||||||
|
input_path
|
||||||
|
]).await?;
|
||||||
|
|
||||||
|
let output = FFProbeOutput::parse(&output.stdout)?;
|
||||||
|
|
||||||
|
Ok(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue