diff --git a/src/utils/transcoder/presets/g726.rs b/src/utils/transcoder/presets/g726.rs index 9cc7ccf..16018ef 100644 --- a/src/utils/transcoder/presets/g726.rs +++ b/src/utils/transcoder/presets/g726.rs @@ -14,6 +14,7 @@ pub fn add_presets(preset_categories: &mut Vec) { sample_rate: Some("8000".to_string()), channels: Some("1".to_string()), bitrate: Some(format!("{}k", bitrate).to_string()), + album_art_codec: Some("h264".to_string()), ..TranscodeConfig::default() }, }) diff --git a/src/utils/transcoder/progress_monitor.rs b/src/utils/transcoder/progress_monitor.rs index 6dc721e..b7e2405 100644 --- a/src/utils/transcoder/progress_monitor.rs +++ b/src/utils/transcoder/progress_monitor.rs @@ -102,7 +102,13 @@ pub fn progress_monitor( match res.kind { EventKind::Modify(_) => { - let mut file = fs::File::open(&file_path).unwrap(); + let file = fs::File::open(&file_path); + let mut file = match file { + Ok(f) => f, + Err(_e) => { + break 'outer; + } + }; file.seek(SeekFrom::Start(pos)).unwrap(); pos = file.metadata().unwrap().len(); diff --git a/src/utils/transcoder/transcoder.rs b/src/utils/transcoder/transcoder.rs index 45b38fd..6fdaaf1 100644 --- a/src/utils/transcoder/transcoder.rs +++ b/src/utils/transcoder/transcoder.rs @@ -43,6 +43,27 @@ pub fn transcode( command_args.extend(vec!["-b:a".to_string(), bitrate.to_string()]); } + if let Some(album_art_codec) = &config.album_art_codec { + println!("{}", album_art_codec); + command_args.extend(vec!["-c:v".to_string(), album_art_codec.to_string()]); + + if config.album_art_height.is_some() && config.album_art_width.is_some() { + let mut height: i16 = config.album_art_height.unwrap() as i16; + if height == 0 { + height = -1; + } + + let mut width = config.album_art_width.unwrap() as i16; + if width == 0 { + width = -1; + } + + command_args.extend(vec!["-vf".to_string(), format!("scale={}:{}", width, height)]); + println!("{:#?}", command_args); + } + + } + command_args.push(dest); let mut progress_thread: Option> = None; @@ -72,7 +93,7 @@ pub fn transcode( } if let Some(thread) = progress_thread { - fs::remove_file(progress_file.unwrap())?; + let _ = fs::remove_file(progress_file.unwrap()); thread.join().expect("thread couldn't join"); } diff --git a/src/utils/transcoder/types.rs b/src/utils/transcoder/types.rs index e09b964..6c9324a 100644 --- a/src/utils/transcoder/types.rs +++ b/src/utils/transcoder/types.rs @@ -24,6 +24,9 @@ pub struct TranscodeConfig { pub quality: Option, pub sample_rate: Option, pub channels: Option, + pub album_art_codec: Option, + pub album_art_height: Option, + pub album_art_width: Option, } impl TranscodeConfig {