diff --git a/backend/src/encoder.rs b/backend/src/encoder.rs index 0c82a23..0811855 100644 --- a/backend/src/encoder.rs +++ b/backend/src/encoder.rs @@ -1,6 +1,7 @@ use std::{env, fs}; use std::path::Path; use std::process::{Command, Output}; +use std::time::Instant; use serde::{Deserialize}; use anyhow::{Context, Result}; use tempdir::TempDir; @@ -35,17 +36,21 @@ impl Encoders { } pub fn exec_all(&self, orig: &str, out: &Path) -> Result<()> { - for enc in self.encoders { - let enc_out = out.with_extension(enc.suffix); + for enc in &self.encoders { + let enc_out = out.with_extension(enc.suffix.to_owned()); // Skip if encoded video already exists if enc_out.exists() { continue } + debug!("Encoding '{}' for {orig}...", enc.name); + let start = Instant::now(); + // Create tmp (this is to prevent partially completed encoding results being detected as completed) let tmp_dir = TempDir::new("meow_encoder_tmp")?; let tmp_out = tmp_dir.path().join(out.file_name().context("No file name")?); // Convert to tmp enc.execute(orig, tmp_out.to_str().context("Call to path.to_str failed")?)?; + debug!("Done, took {:.2} minutes, copying result...", start.elapsed().as_secs_f32() / 60.0); // Copy results fs::copy(tmp_out, enc_out)?; diff --git a/backend/src/generator.rs b/backend/src/generator.rs index 165b1e0..ac08705 100644 --- a/backend/src/generator.rs +++ b/backend/src/generator.rs @@ -103,6 +103,9 @@ impl Generator { /// Process a directory pub fn encode_dir(&self, dir: &PathBuf) -> Result<()> { // Found file + for f in self.list_video_files(dir) { + self.encoders.exec_all(f.to_str().context("Path.to_str failed")?, self.dot_path(&f).as_path())?; + } Ok(()) } diff --git a/backend/src/test.rs b/backend/src/test.rs index 4265644..da21d0e 100644 --- a/backend/src/test.rs +++ b/backend/src/test.rs @@ -39,4 +39,6 @@ fn main() { let videos: Vec = gen.list_video_files(&PathBuf::from("/data/Anime")).collect(); videos.iter().for_each(|x| println!("Video found: {}", x.display())); println!("Length: {}", videos.len()); + + gen.encode_dir(&PathBuf::from("/data/Anime")).expect("Encoding failed"); }