add auto preset detection on transcode command
This commit is contained in:
parent
d9154f3373
commit
fb55fc45b1
|
@ -35,10 +35,12 @@ fn extract(
|
|||
}));
|
||||
}
|
||||
|
||||
|
||||
let output = String::from_utf8(output.stdout).unwrap();
|
||||
let ffprobe_out: serde_json::Result<ffprobe_output::FFProbeOutput> =
|
||||
serde_json::from_str(output.as_str());
|
||||
|
||||
|
||||
Ok(ffprobe_out.unwrap())
|
||||
}
|
||||
|
||||
|
|
|
@ -30,24 +30,49 @@ pub fn transcode_command(
|
|||
_args: CLIArgs,
|
||||
transcode_args: &TranscodeCommandArgs,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let Some(preset) = &transcode_args.preset {
|
||||
let input_file = AudioFile::from_path("".to_string(), PathBuf::from(&transcode_args.source));
|
||||
let output_file = AudioFile::from_path("".to_string(), PathBuf::from(&transcode_args.dest));
|
||||
|
||||
let mut preset = transcode_args.preset.clone().unwrap_or("auto".to_string());
|
||||
|
||||
if preset == "list" {
|
||||
print_presets();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if preset == "auto" && transcode_args.transcode_config.is_none() {
|
||||
let extension = output_file
|
||||
.extension()
|
||||
.clone()
|
||||
.expect("a extension is required for the output file");
|
||||
|
||||
preset = match extension.as_str() {
|
||||
"mp3" => "mp3-v2",
|
||||
"opus" => "opus-96k",
|
||||
"flac" => "flac",
|
||||
"ogg" => "vorbis-v6",
|
||||
_ => {
|
||||
println!(
|
||||
"could not auto determine a suitable transcode preset for extension '{}'",
|
||||
output_file.extension().unwrap()
|
||||
);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
.to_string();
|
||||
}
|
||||
|
||||
let transcode_config = transcode_preset_or_config(
|
||||
transcode_args.preset.as_ref(),
|
||||
match transcode_args.transcode_config {
|
||||
Some(_) => None,
|
||||
None => Some(&preset),
|
||||
},
|
||||
transcode_args.transcode_config.as_ref(),
|
||||
)
|
||||
.expect("transcode config error");
|
||||
|
||||
println!("Transcoding");
|
||||
|
||||
let input_file = AudioFile::from_path("".to_string(), PathBuf::from(&transcode_args.source));
|
||||
let output_file = AudioFile::from_path("".to_string(), PathBuf::from(&transcode_args.dest));
|
||||
|
||||
if !transcode_args.ignore_extension {
|
||||
if let Some(ref file_extension) = transcode_config.file_extension {
|
||||
if Some(file_extension) != output_file.extension().as_ref() {
|
||||
|
@ -58,7 +83,8 @@ pub fn transcode_command(
|
|||
"please change it to {} ",
|
||||
"or run with --ignore-extension"
|
||||
),
|
||||
output_file.extension().unwrap(), file_extension
|
||||
output_file.extension().unwrap(),
|
||||
file_extension
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue