implement mp3 bitrate rounding up
This commit is contained in:
parent
343a86657e
commit
e3a4e5b976
3 changed files with 16 additions and 2 deletions
|
|
@ -3,6 +3,17 @@ use super::spawn::{spawn, SpawnError};
|
|||
pub struct FFMpeg {}
|
||||
|
||||
impl FFMpeg {
|
||||
const MP3_BITRATES: [u16; 14] = [
|
||||
32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320,
|
||||
];
|
||||
pub fn round_mp3_bitrate(abr: f32) -> u16 {
|
||||
let abr = abr.ceil() as u16;
|
||||
Self::MP3_BITRATES
|
||||
.into_iter()
|
||||
.find(|f| abr <= *f)
|
||||
.unwrap_or(320)
|
||||
}
|
||||
|
||||
pub async fn convert_to_mp3(
|
||||
input_path: &str,
|
||||
output_path: &str,
|
||||
|
|
|
|||
|
|
@ -131,7 +131,7 @@ impl YtDlpInfo {
|
|||
#[derive(Debug)]
|
||||
pub enum YtDlpError {
|
||||
SpawnError(SpawnError),
|
||||
ErrorMessage(String), // keep it separate type if we ever plan to parse yt-dlp errors
|
||||
ErrorMessage(String), // keep it separate type if we ever plan to parse yt-dlp errors
|
||||
JsonError,
|
||||
}
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ impl From<SpawnError> for YtDlpError {
|
|||
fn from(value: SpawnError) -> Self {
|
||||
match value {
|
||||
SpawnError::ErrorMessage(msg) => Self::ErrorMessage(msg),
|
||||
_ => Self::SpawnError(value)
|
||||
_ => Self::SpawnError(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ use teloxide::dispatching::UpdateHandler;
|
|||
use teloxide::{prelude::*, update_listeners::Polling, utils::command::BotCommands};
|
||||
|
||||
mod dl;
|
||||
use dl::ffmpeg::FFMpeg;
|
||||
use dl::yt_dlp::YtDlp;
|
||||
|
||||
type State = ();
|
||||
|
|
@ -50,6 +51,8 @@ async fn main() -> anyhow::Result<()> {
|
|||
let audio = info.best_audio_format().unwrap();
|
||||
println!("{}", audio);
|
||||
|
||||
println!("abr {}", FFMpeg::round_mp3_bitrate(129.492));
|
||||
|
||||
Ok(())
|
||||
//bot_main().await
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue