integrate ffprobe to set proper width/height and duration, so our videos appear normal

This commit is contained in:
mykola2312 2024-09-13 11:27:44 +03:00
parent 42fbf46fd7
commit 7fb9791c2f
2 changed files with 19 additions and 11 deletions

View file

@ -140,12 +140,14 @@ enum Command {
use crate::dl::ffprobe::FFProbe; use crate::dl::ffprobe::FFProbe;
async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult { async fn cmd_test(bot: Bot, msg: Message, _db: DbPool) -> HandlerResult {
if let Ok(probe) = FFProbe::probe("/home/mykola/Videos/test-video").await { if cfg!(debug_assertions) {
if let Some(vs) = probe.get_video_stream() { if let Ok(probe) = FFProbe::probe("/home/mykola/Videos/test-video").await {
dbg!(vs.get_video_resolution()); if let Some(vs) = probe.get_video_stream() {
dbg!(vs.get_video_resolution());
}
} else {
dbg!("failed");
} }
} else {
dbg!("failed");
} }
Ok(()) Ok(())

View file

@ -17,13 +17,19 @@ async fn bot_download(bot: Bot, msg: Message, url: String) -> HandlerResult {
} }
}; };
// query media info with
// ffprobe -v quiet -print_format json -show_streams -select_streams v:0 input.mp4
let probe = FFProbe::probe(&output.path).await;
dbg!(probe);
let mut video = bot.send_video(msg.chat.id, InputFile::file(&output.path)); let mut video = bot.send_video(msg.chat.id, InputFile::file(&output.path));
// set width, height and so on // try getting video resolution
if let Ok(probe) = FFProbe::probe(&output.path).await {
if let Some(vs) = probe.get_video_stream() {
if let Some((width, height)) = vs.get_video_resolution() {
video.width = Some(width);
video.height = Some(height);
}
// set video duration
video.duration = Some(vs.duration as u32);
}
}
video.await?; video.await?;