diff --git a/examples/main.rs b/examples/main.rs index a8a5cad..0b7cb8f 100644 --- a/examples/main.rs +++ b/examples/main.rs @@ -6,7 +6,6 @@ fn main() -> anyhow::Result<()> { let mut arg = env::args(); arg.next(); // skip executable let filename = arg.next().ok_or(anyhow::anyhow!("unexpected"))?; - let frames = arg.next().unwrap_or("frames".into()); - decode_to_files(&filename, &frames)?; + decode_to_files(&filename)?; Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 4731b9a..f3ea571 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -251,15 +251,26 @@ fn decode(filename: &str) -> PyResult { Ok(iter.into()) } -pub fn decode_to_files(filename: &str, frames_root: &str) -> anyhow::Result<()> { +/// writes to frames/ +pub fn decode_to_files(filename: &str) -> anyhow::Result<()> { let frameiter = Decoder::new(filename)?; + let basename = std::path::Path::new(filename) + .file_stem() + .ok_or(anyhow::anyhow!("cannot get basename"))? + .to_str() + .ok_or(anyhow::anyhow!("cannot convert to utf-8 from os name"))?; + let target_dir = format!("frames/{}", basename); + let target_dir = std::path::Path::new(&target_dir); + if !target_dir.exists() { + std::fs::create_dir(target_dir)?; + } for (i, frame) in frameiter.enumerate() { - let name = format!("{}/{:05}.png", frames_root, i); + let name = format!("frames/{}/{:05}.png", basename, i); if let Err(_e) = write_raw_frame(&name, &frame.raw) { println!("skipping bad frame {}", i); continue; } - let name = format!("{}/temp_{:05}.png", frames_root, i); + let name = format!("{}/temp_{:05}.png", target_dir.display(), i); let pixels = frame.pixels(); write_calibrated_frame(&name, &pixels)?; } diff --git a/thermal.mp4 b/thermal.mp4 index 4665d9b..cd76de9 100644 Binary files a/thermal.mp4 and b/thermal.mp4 differ