[+] encode_dir

This commit is contained in:
Azalea Gui
2023-02-24 12:30:18 -05:00
parent ee67670a89
commit 215564523c
3 changed files with 12 additions and 2 deletions
+7 -2
View File
@@ -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)?;
+3
View File
@@ -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(())
}
+2
View File
@@ -39,4 +39,6 @@ fn main() {
let videos: Vec<PathBuf> = 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");
}