pause/resume with segment concat
This commit is contained in:
@@ -236,6 +236,45 @@ fn estimate_gif_scale_width(req: &TranscodeRequest) -> u32 {
|
||||
(w / 2) * 2
|
||||
}
|
||||
|
||||
pub fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Result<()> {
|
||||
if segments.is_empty() {
|
||||
bail!("no segments to concatenate");
|
||||
}
|
||||
if segments.len() == 1 {
|
||||
std::fs::copy(&segments[0], output).context("copying single segment")?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let parent = output
|
||||
.parent()
|
||||
.ok_or_else(|| anyhow!("output has no parent dir"))?;
|
||||
std::fs::create_dir_all(parent).context("creating output parent dir")?;
|
||||
|
||||
let list_path = parent.join("concat-list.txt");
|
||||
let mut body = String::new();
|
||||
for seg in segments {
|
||||
let s = seg
|
||||
.to_str()
|
||||
.ok_or_else(|| anyhow!("segment path is not UTF-8"))?
|
||||
.replace('\\', "/");
|
||||
body.push_str(&format!("file '{s}'\n"));
|
||||
}
|
||||
std::fs::write(&list_path, body).context("writing concat list")?;
|
||||
|
||||
let mut cmd = Command::new(ffmpeg);
|
||||
cmd.arg("-y")
|
||||
.arg("-hide_banner")
|
||||
.args(["-f", "concat"])
|
||||
.args(["-safe", "0"])
|
||||
.arg("-i")
|
||||
.arg(&list_path)
|
||||
.args(["-c", "copy"])
|
||||
.arg(output);
|
||||
let result = run(&mut cmd, "concat");
|
||||
let _ = std::fs::remove_file(&list_path);
|
||||
result
|
||||
}
|
||||
|
||||
fn run(cmd: &mut Command, label: &str) -> Result<()> {
|
||||
let mut printable = OsString::from(label);
|
||||
printable.push(": ");
|
||||
|
||||
Reference in New Issue
Block a user