enforce stricter lints, drop discarded results properly
This commit is contained in:
+36
-36
@@ -65,8 +65,8 @@ const BOX_HALF: i32 = BOX_SIZE / 2;
|
||||
|
||||
/// What `click_filters` needs to place the highlight boxes.
|
||||
fn click_box(clip_x: i32, clip_y: i32, clip_w: u32, clip_h: u32) -> Option<(i32, i32)> {
|
||||
let vw = clip_w as i32;
|
||||
let vh = clip_h as i32;
|
||||
let vw = clip_w.cast_signed();
|
||||
let vh = clip_h.cast_signed();
|
||||
// Only suppress when the point lies entirely outside the frame, so a click
|
||||
// just inside an edge still gets the sliver of box that is visible.
|
||||
let outside = clip_x + BOX_HALF <= 0
|
||||
@@ -393,7 +393,7 @@ fn two_pass_video(
|
||||
|
||||
// Send 50% to signal pass 1 done, pass 2 starting.
|
||||
if let Some(ref t) = tx {
|
||||
let _ = t.send(EncodeProgress { pass: 1, total_passes: 2, percent: 100.0 });
|
||||
drop(t.send(EncodeProgress { pass: 1, total_passes: 2, percent: 100.0 }));
|
||||
}
|
||||
|
||||
let mut pass2 = Command::new(ffmpeg);
|
||||
@@ -453,7 +453,7 @@ fn cleanup_pass_logs(stem: &Path) {
|
||||
let name = entry.file_name();
|
||||
if let Some(name_str) = name.to_str() {
|
||||
if name_str.starts_with(prefix) {
|
||||
let _ = std::fs::remove_file(entry.path());
|
||||
drop(std::fs::remove_file(entry.path()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -503,13 +503,13 @@ fn calibrate_via_sample(
|
||||
// clip overstates per-frame cost slightly (less inter-frame reuse) so we
|
||||
// apply a small correction factor toward the conservative side.
|
||||
let aspect = aspect_ratio(req.clip_width, req.clip_height);
|
||||
let sample_h = (est_width as f64 / aspect).round() as u32;
|
||||
let frames = (est_fps as f64 * sample_dur).max(1.0);
|
||||
let measured_bpp = sample_bytes as f64 / (est_width as f64 * sample_h as f64 * frames);
|
||||
let sample_h = (f64::from(est_width) / aspect).round() as u32;
|
||||
let frames = (f64::from(est_fps) * sample_dur).max(1.0);
|
||||
let measured_bpp = sample_bytes as f64 / (f64::from(est_width) * f64::from(sample_h) * frames);
|
||||
// Blend toward the assumed 0.2 constant - don't over-trust a 2s sample.
|
||||
let blended_bpp = measured_bpp * 0.7 + 0.2 * 0.3;
|
||||
|
||||
let color_factor = (req.gif_colors as f64 / 256.0).sqrt().clamp(0.15, 1.0);
|
||||
let color_factor = (f64::from(req.gif_colors) / 256.0).sqrt().clamp(0.15, 1.0);
|
||||
let assumed_bpp = 0.2 * color_factor;
|
||||
let ratio = assumed_bpp / blended_bpp;
|
||||
// Only recalibrate if the gap is meaningful (>15%). Small gaps aren't
|
||||
@@ -520,8 +520,8 @@ fn calibrate_via_sample(
|
||||
|
||||
// Recompute target params with the corrected constant. Scale resolution
|
||||
// by the sqrt of the ratio so file size scales roughly linearly.
|
||||
let new_width = ((est_width as f64 * ratio.sqrt()).round() as u32 / 2).max(60) * 2;
|
||||
let new_fps = ((est_fps as f64 * ratio.sqrt()).round() as u32).max(1).min(est_fps);
|
||||
let new_width = ((f64::from(est_width) * ratio.sqrt()).round() as u32 / 2).max(60) * 2;
|
||||
let new_fps = ((f64::from(est_fps) * ratio.sqrt()).round() as u32).max(1).min(est_fps);
|
||||
Some((new_width.min(1280), new_fps))
|
||||
}
|
||||
|
||||
@@ -647,15 +647,15 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
||||
GifBudgetMode::Resolution => {
|
||||
// Halve before clamping so the *2 keeps the width even.
|
||||
scale_width =
|
||||
((scale_width as f64 * factor).round() as u32 / 2).clamp(60, 640) * 2;
|
||||
((f64::from(scale_width) * factor).round() as u32 / 2).clamp(60, 640) * 2;
|
||||
}
|
||||
GifBudgetMode::Framerate => {
|
||||
effective_fps = ((effective_fps as f64 * factor).round() as u32).max(1);
|
||||
effective_fps = ((f64::from(effective_fps) * factor).round() as u32).max(1);
|
||||
}
|
||||
GifBudgetMode::Balanced => {
|
||||
scale_width =
|
||||
((scale_width as f64 * factor).round() as u32 / 2).clamp(60, 640) * 2;
|
||||
effective_fps = ((effective_fps as f64 * factor).round() as u32).max(1);
|
||||
((f64::from(scale_width) * factor).round() as u32 / 2).clamp(60, 640) * 2;
|
||||
effective_fps = ((f64::from(effective_fps) * factor).round() as u32).max(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -770,18 +770,18 @@ pub fn gif_params(input: &GifBudgetInput, clip_width: u32, clip_height: u32) ->
|
||||
// Fewer colors = better compression. Adjust proportionally to the sqrt of the color
|
||||
// fraction (LZW code width tracks palette depth roughly logarithmically).
|
||||
// 256 colors = 1.0x, 128 = ~0.71x, 64 = 0.5x, 32 = ~0.35x, 16 = 0.25x, 2 = ~0.13x
|
||||
let color_factor = (input.gif_colors as f64 / 256.0).sqrt().clamp(0.15, 1.0);
|
||||
let color_factor = (f64::from(input.gif_colors) / 256.0).sqrt().clamp(0.15, 1.0);
|
||||
let bytes_per_pixel_per_frame = 0.2 * color_factor;
|
||||
let target_bytes = input.target_bytes as f64;
|
||||
let requested_fps = input.fps as f64;
|
||||
let requested_fps = f64::from(input.fps);
|
||||
let duration = input.duration_secs;
|
||||
|
||||
match input.gif_budget_mode {
|
||||
GifBudgetMode::Resolution => {
|
||||
let max_w = (clip_width.min(1280) as f64).clamp(120.0, 1280.0);
|
||||
let max_w = f64::from(clip_width.min(1280)).clamp(120.0, 1280.0);
|
||||
let w = (max_w / 2.0).round() as u32 * 2;
|
||||
let h = (w as f64 / aspect).round() as u32;
|
||||
let pixels_per_frame = w as f64 * h as f64;
|
||||
let h = (f64::from(w) / aspect).round() as u32;
|
||||
let pixels_per_frame = f64::from(w) * f64::from(h);
|
||||
let bytes_per_frame = pixels_per_frame * bytes_per_pixel_per_frame;
|
||||
let max_frames = (target_bytes / bytes_per_frame).floor().max(1.0);
|
||||
let min_fps = (max_frames / duration).max(1.0).round() as u32;
|
||||
@@ -800,14 +800,14 @@ pub fn gif_params(input: &GifBudgetInput, clip_width: u32, clip_height: u32) ->
|
||||
let budget_at_full = target_bytes / (frames_at_full * bytes_per_pixel_per_frame);
|
||||
let w_at_full = (budget_at_full * aspect).sqrt().clamp(120.0, 1280.0);
|
||||
|
||||
let scale = if w_at_full < clip_width as f64 {
|
||||
(w_at_full / clip_width as f64).sqrt()
|
||||
let scale = if w_at_full < f64::from(clip_width) {
|
||||
(w_at_full / f64::from(clip_width)).sqrt()
|
||||
} else {
|
||||
1.0
|
||||
};
|
||||
let scale = scale.max(0.1);
|
||||
|
||||
let w = ((clip_width as f64 * scale).round() as u32 / 2).max(60) * 2;
|
||||
let w = ((f64::from(clip_width) * scale).round() as u32 / 2).max(60) * 2;
|
||||
let fps = ((requested_fps * scale).round() as u32).max(1).min(input.fps);
|
||||
(w, fps)
|
||||
}
|
||||
@@ -816,7 +816,7 @@ pub fn gif_params(input: &GifBudgetInput, clip_width: u32, clip_height: u32) ->
|
||||
|
||||
pub fn aspect_ratio(width: u32, height: u32) -> f64 {
|
||||
if height > 0 {
|
||||
width as f64 / height as f64
|
||||
f64::from(width) / f64::from(height)
|
||||
} else {
|
||||
16.0 / 9.0
|
||||
}
|
||||
@@ -827,7 +827,7 @@ pub fn gif_height_for_width(width: u32, clip_width: u32, clip_height: u32) -> u3
|
||||
if width == 0 {
|
||||
0
|
||||
} else {
|
||||
((width as f64 / aspect).round() as u32 / 2) * 2
|
||||
((f64::from(width) / aspect).round() as u32 / 2) * 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -915,7 +915,7 @@ pub fn render_gif_preview(
|
||||
.args(["-frames:v", "1"])
|
||||
.arg(out_path);
|
||||
let result = run(&mut encode, "gif preview encode");
|
||||
let _ = std::fs::remove_file(&palette_path);
|
||||
drop(std::fs::remove_file(&palette_path));
|
||||
result
|
||||
}
|
||||
|
||||
@@ -934,7 +934,7 @@ fn clean_stale_palettes(dir: &Path) {
|
||||
for entry in entries.flatten() {
|
||||
if let Some(name) = entry.file_name().to_str() {
|
||||
if name.starts_with("preview-palette-") && name.ends_with(".png") {
|
||||
let _ = std::fs::remove_file(entry.path());
|
||||
drop(std::fs::remove_file(entry.path()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -950,7 +950,7 @@ pub fn extract_thumbnails(
|
||||
) -> Result<Vec<PathBuf>> {
|
||||
std::fs::create_dir_all(out_dir).context("creating thumbnails dir")?;
|
||||
for entry in std::fs::read_dir(out_dir).into_iter().flatten().flatten() {
|
||||
let _ = std::fs::remove_file(entry.path());
|
||||
drop(std::fs::remove_file(entry.path()));
|
||||
}
|
||||
|
||||
let crop_prefix = crop_filter(crop)
|
||||
@@ -1035,7 +1035,7 @@ pub fn concat_pcm(segments: &[PathBuf], output: &Path) -> Result<()> {
|
||||
|
||||
struct TempFileGuard(PathBuf);
|
||||
impl Drop for TempFileGuard {
|
||||
fn drop(&mut self) { let _ = std::fs::remove_file(&self.0); }
|
||||
fn drop(&mut self) { drop(std::fs::remove_file(&self.0)); }
|
||||
}
|
||||
|
||||
pub fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Result<()> {
|
||||
@@ -1190,11 +1190,11 @@ fn run_impl(
|
||||
} else if key == "progress" {
|
||||
let percent = (last_out_time_us / encode_dur_us * 100.0).clamp(0.0, 100.0);
|
||||
if let Some(ref sender) = tx {
|
||||
let _ = sender.send(EncodeProgress {
|
||||
drop(sender.send(EncodeProgress {
|
||||
pass,
|
||||
total_passes,
|
||||
percent,
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1208,7 +1208,7 @@ fn run_impl(
|
||||
let mut collected = Vec::new();
|
||||
use std::io::Read;
|
||||
let mut s = serr;
|
||||
let _ = s.read_to_end(&mut collected);
|
||||
drop(s.read_to_end(&mut collected));
|
||||
collected
|
||||
})
|
||||
});
|
||||
@@ -1216,16 +1216,16 @@ fn run_impl(
|
||||
loop {
|
||||
if let Some(ref c) = cancel {
|
||||
if c.load(Ordering::Relaxed) {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
if let Some(h) = stdout_handle.take() { let _ = h.join(); }
|
||||
if let Some(h) = stderr_handle.take() { let _ = h.join(); }
|
||||
drop(child.kill());
|
||||
drop(child.wait());
|
||||
if let Some(h) = stdout_handle.take() { drop(h.join()); }
|
||||
if let Some(h) = stderr_handle.take() { drop(h.join()); }
|
||||
bail!("export cancelled");
|
||||
}
|
||||
}
|
||||
match child.try_wait() {
|
||||
Ok(Some(status)) => {
|
||||
if let Some(h) = stdout_handle.take() { let _ = h.join(); }
|
||||
if let Some(h) = stdout_handle.take() { drop(h.join()); }
|
||||
let stderr_bytes = stderr_handle.take()
|
||||
.and_then(|h| h.join().ok())
|
||||
.unwrap_or_default();
|
||||
|
||||
Reference in New Issue
Block a user