[READ-ONLY] Mirror of https://github.com/mrgnw/avify.
0

Configure Feed

Select the types of activity you want to include in your feed.

show progress counter [n/total] during encoding

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+14 -8
+14 -8
src/main.rs
··· 5 5 use rayon::prelude::*; 6 6 use std::fs; 7 7 use std::path::PathBuf; 8 + use std::sync::atomic::{AtomicUsize, Ordering}; 8 9 9 10 #[derive(Parser)] 10 11 #[command(about = "Convert camera RAW files to AVIF")] ··· 52 53 Ok(avif_file) 53 54 } 54 55 55 - fn process_file(path: &PathBuf, quality: f32, speed: u8) -> Result<()> { 56 + fn process_file( 57 + path: &PathBuf, 58 + quality: f32, 59 + speed: u8, 60 + done: &AtomicUsize, 61 + total: usize, 62 + ) -> Result<()> { 56 63 let out_path = path.with_extension("avif"); 64 + let name = path.file_name().unwrap_or_default().to_string_lossy(); 57 65 58 66 let img = decode_raw(path).with_context(|| format!("Failed to decode {}", path.display()))?; 59 67 let avif_data = encode_avif(img, quality, speed)?; ··· 61 69 fs::write(&out_path, &avif_data) 62 70 .with_context(|| format!("Failed to write {}", out_path.display()))?; 63 71 64 - println!( 65 - "{} → {} ({}KB)", 66 - path.display(), 67 - out_path.display(), 68 - avif_data.len() / 1024 69 - ); 72 + let n = done.fetch_add(1, Ordering::Relaxed) + 1; 73 + println!("[{n}/{total}] {name} → {}KB", avif_data.len() / 1024); 70 74 Ok(()) 71 75 } 72 76 73 77 fn main() -> Result<()> { 74 78 let args = Args::parse(); 79 + let total = args.files.len(); 80 + let done = AtomicUsize::new(0); 75 81 76 82 args.files 77 83 .par_iter() 78 - .try_for_each(|path| process_file(path, args.quality, args.speed))?; 84 + .try_for_each(|path| process_file(path, args.quality, args.speed, &done, total))?; 79 85 80 86 Ok(()) 81 87 }