-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
100 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use super::fps_reader::get_fps; | ||
use crate::{ | ||
commanders, | ||
helpers::{ | ||
io_helper::path_bufs_to_sorted_strings, str_helper::gen_input_file_content_for_ffmpeg, | ||
}, | ||
}; | ||
use std::{ | ||
collections::{HashMap, HashSet}, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
pub fn change_fps( | ||
files_to_merge: Vec<PathBuf>, | ||
tmp_dir: &Path, | ||
fps_from_cli: f32, | ||
) -> (Vec<PathBuf>, Vec<std::string::String>, std::string::String) { | ||
let mut new_files_to_merge = Vec::new(); | ||
let mut map: HashMap<&PathBuf, f32> = HashMap::new(); | ||
|
||
for file_to_merge in &files_to_merge { | ||
map.insert(file_to_merge, get_fps(file_to_merge)); | ||
} | ||
|
||
let fps_goal = if fps_from_cli != 0. { | ||
fps_from_cli | ||
} else { | ||
*map.values() | ||
.min_by(|x, y| x.partial_cmp(y).unwrap()) | ||
.unwrap() | ||
}; | ||
|
||
let set: HashSet<String> = map.values().map(|value| value.to_string()).collect(); | ||
let files_to_merge = if set.len() > 1 { | ||
println!("----------------------------------------------------------------"); | ||
println!("🔎 FPS mismatches detected"); | ||
println!(); | ||
println!("Will be merged directly: \n"); | ||
let mut output = Vec::new(); | ||
for (key, value) in &map { | ||
if value == &fps_goal { | ||
output.push(format!( | ||
"- {} ({} fps)", | ||
key.file_name().unwrap().to_string_lossy(), | ||
value | ||
)); | ||
} | ||
} | ||
output.sort(); | ||
for line in output { | ||
println!("{}", line); | ||
} | ||
println!(); | ||
println!("Will be merged indirectly, generating new files from listed below with {} fps and merges with listed above:", fps_goal); | ||
println!(); | ||
let mut output = Vec::new(); | ||
for (key, value) in &map { | ||
if value != &fps_goal { | ||
output.push(format!( | ||
"- {} ({} fps)", | ||
key.file_name().unwrap().to_string_lossy(), | ||
value | ||
)); | ||
} | ||
} | ||
output.sort(); | ||
for line in output { | ||
println!("{}", line); | ||
} | ||
println!("----------------------------------------------------------------"); | ||
println!("🚀 Start FPS Changer, calling:"); | ||
println!(); | ||
for file_to_merge in files_to_merge { | ||
let fps = get_fps(&file_to_merge); | ||
|
||
if fps != fps_goal { | ||
let new_file_to_merge = | ||
commanders::fps_adjuster::adjust_fps(file_to_merge, &fps_goal, tmp_dir); | ||
new_files_to_merge.push(new_file_to_merge); | ||
} else { | ||
new_files_to_merge.push(file_to_merge); | ||
} | ||
} | ||
|
||
new_files_to_merge | ||
} else { | ||
files_to_merge | ||
}; | ||
|
||
let files_to_merge_as_strings = path_bufs_to_sorted_strings(&files_to_merge); | ||
let ffmpeg_input_content = gen_input_file_content_for_ffmpeg(&files_to_merge_as_strings); | ||
|
||
( | ||
files_to_merge, | ||
files_to_merge_as_strings, | ||
ffmpeg_input_content, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters