merge duplicate arms and drop a needless clone
This commit is contained in:
+21
-20
@@ -532,27 +532,28 @@ fn calibrate_via_sample(
|
||||
let sample_dur = 2.0_f64.min(req.duration_secs);
|
||||
let sample_start = (req.duration_secs / 2.0 - sample_dur / 2.0).max(0.0);
|
||||
|
||||
// Build a throwaway request scoped to the sample window.
|
||||
let mut sample_req = req.clone();
|
||||
sample_req.output = sample_path.clone();
|
||||
sample_req.trim_start_secs = Some(sample_start);
|
||||
sample_req.trim_end_secs = Some(sample_start + sample_dur);
|
||||
sample_req.deleted_frame_indices.clear();
|
||||
sample_req.clicks.clear();
|
||||
sample_req.progress_tx = None;
|
||||
// Defer cleanup until we've measured the sample: the guard owns a copy of
|
||||
// the path, which lets the original move into the request below. Earlier
|
||||
// versions removed the file here, which made the metadata read always fail
|
||||
// and the whole calibration path silently no-op.
|
||||
let sample_bytes;
|
||||
{
|
||||
let _guard = TempFileGuard(sample_path.clone());
|
||||
|
||||
let result = encode_gif_pass(ffmpeg, &sample_req, est_width, est_fps, 1, 1);
|
||||
// Defer cleanup until we've measured the sample. Earlier versions removed
|
||||
// the file here, which made the metadata read below always fail and the
|
||||
// whole calibration path silently no-op.
|
||||
let _guard = TempFileGuard(sample_path.clone());
|
||||
if result.is_err() {
|
||||
return None;
|
||||
// Build a throwaway request scoped to the sample window.
|
||||
let mut sample_req = req.clone();
|
||||
sample_req.output = sample_path;
|
||||
sample_req.trim_start_secs = Some(sample_start);
|
||||
sample_req.trim_end_secs = Some(sample_start + sample_dur);
|
||||
sample_req.deleted_frame_indices.clear();
|
||||
sample_req.clicks.clear();
|
||||
sample_req.progress_tx = None;
|
||||
|
||||
if encode_gif_pass(ffmpeg, &sample_req, est_width, est_fps, 1, 1).is_err() {
|
||||
return None;
|
||||
}
|
||||
sample_bytes = std::fs::metadata(&_guard.0).map(|m| m.len()).ok()?;
|
||||
}
|
||||
let sample_bytes = match std::fs::metadata(&sample_path) {
|
||||
Ok(m) => m.len(),
|
||||
Err(_) => return None,
|
||||
};
|
||||
if sample_bytes == 0 {
|
||||
return None;
|
||||
}
|
||||
@@ -1118,13 +1119,13 @@ pub(crate) fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path
|
||||
|
||||
let list_path = parent.join("concat-list.txt");
|
||||
let _guard = TempFileGuard(list_path.clone());
|
||||
use std::fmt::Write as _;
|
||||
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('\\', "/");
|
||||
use std::fmt::Write as _;
|
||||
let _ = writeln!(body, "file '{s}'");
|
||||
}
|
||||
std::fs::write(&list_path, body).context("writing concat list")?;
|
||||
|
||||
Reference in New Issue
Block a user