rust: create target dir, use frames/basename as decode.py

This commit is contained in:
Alon Levy 2023-12-31 14:17:03 +02:00
parent 862a48131e
commit 3ea0c74e7f
3 changed files with 15 additions and 5 deletions

View File

@ -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(())
}

View File

@ -251,15 +251,26 @@ fn decode(filename: &str) -> PyResult<PyFrameIterator> {
Ok(iter.into())
}
pub fn decode_to_files(filename: &str, frames_root: &str) -> anyhow::Result<()> {
/// writes to frames/<basename of filename>
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)?;
}

Binary file not shown.