Compare commits

...

2 Commits

Author SHA1 Message Date
Alon Levy
d6c5058f2e add rustdecode.sh 2023-12-31 14:18:30 +02:00
Alon Levy
3ea0c74e7f rust: create target dir, use frames/basename as decode.py 2023-12-31 14:17:03 +02:00
4 changed files with 17 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(())
}

2
rustdecode.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
cargo run --release --example main -- "$@"

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.