Skip to content

Commit

Permalink
Update main.rs
Browse files Browse the repository at this point in the history
fixed ffmpeg bug
  • Loading branch information
alexjsteffen authored Jun 23, 2024
1 parent 101fb14 commit 3436cb0
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,29 @@ fn combine_audio_files(input_file_path: &Path, output_dir: &Path) -> Result<()>
})
.collect();

let concat_file_path = output_dir.join("concat.txt");
let mut concat_file = File::create(&concat_file_path)?;
for flac_file in &flac_files {
writeln!(concat_file, "file '{}'", flac_file.file_name().unwrap().to_str().unwrap())?;
}
let concat_file_path = output_dir.join("concat.txt");
let mut concat_file = File::create(&concat_file_path)?;
for flac_file in &flac_files {
writeln!(concat_file, "file '{}'", flac_file.to_str().unwrap())?;
}

let output_file_path = output_dir.join(format!("{}.flac", input_file_name));
let status = Command::new("ffmpeg")
.args(
&[
"-f",
"concat",
"-safe",
"0",
"-i",
concat_file_path.to_str().unwrap(),
"-c:a",
"flac",
output_file_path.to_str().unwrap(),
]
)
.status()?;

let output_file_path = output_dir.join(format!("{}.flac", input_file_name));
let status = Command::new("ffmpeg")
.args(
&[
"-i",
concat_file_path.to_str().unwrap(),
"-c:a",
"flac",
output_file_path.to_str().unwrap(),
]
)
.status()?;

if !status.success() {
anyhow::bail!("ffmpeg command failed");
Expand All @@ -234,4 +239,4 @@ fn remove_tmp(output_dir: &Path) -> Result<()> {
}
fs::remove_file(output_dir.join("concat.txt"))?;
Ok(())
}
}

0 comments on commit 3436cb0

Please sign in to comment.