tighten visibility and clear the remaining mechanical lint noise

This commit is contained in:
2026-09-21 00:44:25 +03:00
parent 1332600148
commit 03b2fec744
11 changed files with 158 additions and 172 deletions
+25 -30
View File
@@ -19,17 +19,17 @@ const AUDIO_BITRATE_KBPS: u64 = 192;
/// Progress update sent during encoding.
/// pass: 1-based pass number (1 or 2 for two-pass video, 1 for GIF).
/// total_passes: total number of passes.
/// `total_passes`: total number of passes.
/// percent: 0.0 to 100.0.
#[derive(Debug, Clone, Copy, serde::Serialize)]
pub struct EncodeProgress {
pub(crate) struct EncodeProgress {
pub pass: u8,
pub total_passes: u8,
pub percent: f64,
}
#[derive(Debug, Clone)]
pub struct TranscodeRequest {
pub(crate) struct TranscodeRequest {
pub input: PathBuf,
pub output: PathBuf,
pub format: Format,
@@ -151,7 +151,7 @@ fn crop_filter(crop: Option<CaptureRect>) -> Option<String> {
})
}
pub fn transcode(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
pub(crate) fn transcode(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
if req.duration_secs <= 0.01 {
bail!("clip duration is essentially zero - nothing to encode");
}
@@ -284,7 +284,7 @@ fn webm_video_codec(c: WebmCodec) -> &'static str {
/// codecs (H265, AV1) are reported because those are the ones users pick to
/// save size and only learn at minute 5 that their build lacks them.
#[derive(Debug, Clone, serde::Serialize)]
pub struct CodecAvailability {
pub(crate) struct CodecAvailability {
pub h264: bool,
pub h265: bool,
pub vp9: bool,
@@ -294,12 +294,12 @@ pub struct CodecAvailability {
impl CodecAvailability {
/// Returns all-true when ffmpeg is not installed yet (the bootstrap screen
/// is still up). Settings will re-query after the user installs ffmpeg.
pub fn all_unknown() -> Self {
pub(crate) fn all_unknown() -> Self {
Self { h264: true, h265: true, vp9: true, av1: true }
}
}
pub fn codec_availability(ffmpeg: &Path) -> CodecAvailability {
pub(crate) fn codec_availability(ffmpeg: &Path) -> CodecAvailability {
let encoders = match list_encoders(ffmpeg) {
Ok(set) => set,
Err(_) => return CodecAvailability::all_unknown(),
@@ -598,8 +598,7 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
);
let actual = std::fs::metadata(&req.output)
.map(|m| m.len())
.unwrap_or(0);
.map_or(0, |m| m.len());
if actual == 0 {
bail!("gif output is empty");
@@ -672,7 +671,7 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
}
// All retries exhausted - warn if still over target
let final_size = std::fs::metadata(&req.output).map(|m| m.len()).unwrap_or(0);
let final_size = std::fs::metadata(&req.output).map_or(0, |m| m.len());
if final_size > req.target_bytes {
tracing::warn!(
"gif encode: could not meet target size after {} attempts. Final: {} bytes (target: {})",
@@ -754,7 +753,7 @@ fn gif_rgb_scale_filter(width: u32) -> String {
}
#[derive(Debug, Clone)]
pub struct GifBudgetInput {
pub(crate) struct GifBudgetInput {
pub gif_colors: u16,
pub target_bytes: u64,
pub fps: u32,
@@ -762,7 +761,7 @@ pub struct GifBudgetInput {
pub gif_budget_mode: GifBudgetMode,
}
pub fn gif_params(input: &GifBudgetInput, clip_width: u32, clip_height: u32) -> (u32, u32) {
pub(crate) fn gif_params(input: &GifBudgetInput, clip_width: u32, clip_height: u32) -> (u32, u32) {
let aspect = aspect_ratio(clip_width, clip_height);
// GIF LZW compression on typical screen content averages ~0.2 bytes/pixel at 256 colors.
// Real compression varies 3-5x depending on content (solid colors compress much better
@@ -814,7 +813,7 @@ pub fn gif_params(input: &GifBudgetInput, clip_width: u32, clip_height: u32) ->
}
}
pub fn aspect_ratio(width: u32, height: u32) -> f64 {
pub(crate) fn aspect_ratio(width: u32, height: u32) -> f64 {
if height > 0 {
f64::from(width) / f64::from(height)
} else {
@@ -822,7 +821,7 @@ pub fn aspect_ratio(width: u32, height: u32) -> f64 {
}
}
pub fn gif_height_for_width(width: u32, clip_width: u32, clip_height: u32) -> u32 {
pub(crate) fn gif_height_for_width(width: u32, clip_width: u32, clip_height: u32) -> u32 {
let aspect = aspect_ratio(clip_width, clip_height);
if width == 0 {
0
@@ -831,7 +830,7 @@ pub fn gif_height_for_width(width: u32, clip_width: u32, clip_height: u32) -> u3
}
}
pub fn render_preview(
pub(crate) fn render_preview(
ffmpeg: &Path,
input: &Path,
out_path: &Path,
@@ -841,7 +840,7 @@ pub fn render_preview(
if let Some(parent) = out_path.parent() {
std::fs::create_dir_all(parent).context("creating preview parent")?;
}
let scale_filter = format!("scale={}:-2", target_width);
let scale_filter = format!("scale={target_width}:-2");
let mut cmd = Command::new(ffmpeg);
cmd.arg("-y")
.arg("-hide_banner")
@@ -856,7 +855,7 @@ pub fn render_preview(
/// Render a GIF preview with actual palette and dithering applied.
/// Generates a palette from the full clip, then applies it to a single frame.
pub fn render_gif_preview(
pub(crate) fn render_gif_preview(
ffmpeg: &Path,
input: &Path,
out_path: &Path,
@@ -923,8 +922,7 @@ pub fn render_gif_preview(
/// actually affect palettegen output. Same inputs -> same palette.
fn palette_cache_key(gif_colors: u16, target_width: u32, sample_start: f64, sample_dur: f64) -> String {
format!(
"c{gif_colors}-w{target_width}-s{:.3}-d{:.3}",
sample_start, sample_dur
"c{gif_colors}-w{target_width}-s{sample_start:.3}-d{sample_dur:.3}"
)
}
@@ -941,7 +939,7 @@ fn clean_stale_palettes(dir: &Path) {
}
}
pub fn extract_thumbnails(
pub(crate) fn extract_thumbnails(
ffmpeg: &Path,
input: &Path,
out_dir: &Path,
@@ -957,9 +955,7 @@ pub fn extract_thumbnails(
.map(|c| format!("{c},"))
.unwrap_or_default();
let filter = format!(
"{prefix}fps={fps},scale=120:-1:flags=lanczos",
prefix = crop_prefix,
fps = fps
"{crop_prefix}fps={fps},scale=120:-1:flags=lanczos"
);
let pattern = out_dir.join("thumb-%05d.png");
@@ -979,15 +975,14 @@ pub fn extract_thumbnails(
p.extension().and_then(|s| s.to_str()) == Some("png")
&& p.file_name()
.and_then(|s| s.to_str())
.map(|s| s.starts_with("thumb-"))
.unwrap_or(false)
.is_some_and(|s| s.starts_with("thumb-"))
})
.collect();
paths.sort();
Ok(paths)
}
pub fn mux_with_audio(
pub(crate) fn mux_with_audio(
ffmpeg: &Path,
video: &Path,
audio_pcm: &Path,
@@ -1016,7 +1011,7 @@ pub fn mux_with_audio(
run(&mut cmd, "mux")
}
pub fn concat_pcm(segments: &[PathBuf], output: &Path) -> Result<()> {
pub(crate) fn concat_pcm(segments: &[PathBuf], output: &Path) -> Result<()> {
use std::io::Write;
if segments.is_empty() {
bail!("no audio segments to concatenate");
@@ -1038,7 +1033,7 @@ impl Drop for TempFileGuard {
fn drop(&mut self) { drop(std::fs::remove_file(&self.0)); }
}
pub fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Result<()> {
pub(crate) fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Result<()> {
if segments.is_empty() {
bail!("no segments to concatenate");
}
@@ -1085,7 +1080,7 @@ fn run(cmd: &mut Command, label: &str) -> Result<()> {
}
/// Run an ffmpeg command with progress monitoring via `-progress pipe:1`.
/// progress_tx, if provided, receives (pass, total_passes, percent) updates
/// `progress_tx`, if provided, receives (pass, `total_passes`, percent) updates
/// driven by ffmpeg's stable key=value output (`out_time_us`) rather than
/// fragile stderr line parsing.
fn run_with_progress(
@@ -1236,7 +1231,7 @@ fn run_impl(
});
}
Ok(None) => {
std::thread::sleep(std::time::Duration::from_millis(20));
thread::sleep(std::time::Duration::from_millis(20));
}
Err(e) => bail!("waiting for ffmpeg: {e}"),
}