[O] Multi-threaded encoding
This commit is contained in:
@@ -9,6 +9,7 @@ use std::fs::{File, Metadata};
|
|||||||
use std::io::{BufReader};
|
use std::io::{BufReader};
|
||||||
use xdg_mime::{SharedMimeInfo};
|
use xdg_mime::{SharedMimeInfo};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use rayon::prelude::*;
|
||||||
use serde::{de, ser};
|
use serde::{de, ser};
|
||||||
use walkdir::{WalkDir, DirEntry};
|
use walkdir::{WalkDir, DirEntry};
|
||||||
use crate::encoder::Encoders;
|
use crate::encoder::Encoders;
|
||||||
@@ -103,11 +104,14 @@ impl Generator {
|
|||||||
/// Process a directory
|
/// Process a directory
|
||||||
pub fn encode_dir(&self, dir: &PathBuf) -> Result<()> {
|
pub fn encode_dir(&self, dir: &PathBuf) -> Result<()> {
|
||||||
// Found file
|
// Found file
|
||||||
for f in self.list_video_files(dir) {
|
let videos: Vec<PathBuf> = self.list_video_files(dir).collect();
|
||||||
self.encoders.exec_all(f.to_str().context("Path.to_str failed")?, self.dot_path(&f).as_path())?;
|
info!("Found {} videos", videos.len());
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
let results: Result<()> = videos.par_iter().map(|f| {
|
||||||
|
Ok(self.encoders.exec_all(f.to_str().context("Path.to_str failed")?, self.dot_path(&f).as_path())?)
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
Ok(results?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List all video files in a directory
|
/// List all video files in a directory
|
||||||
|
|||||||
Reference in New Issue
Block a user