[+] Encoder::exec_all
This commit is contained in:
@@ -2,12 +2,12 @@ processes = 2
|
|||||||
|
|
||||||
[[encoders]]
|
[[encoders]]
|
||||||
name = "H264 Full VBR35"
|
name = "H264 Full VBR35"
|
||||||
cmd = "ffmpeg -i {{INPUT}} -c:v h264_nvenc -cq:v 35 -rc:v vbr -c:a aac -pix_fmt yuv420p -color_primaries 1 -color_trc 1 -colorspace 1 -movflags +faststart {{OUTPUT}}"
|
cmd = "ffmpeg -i {{INPUT}} -nostdin -c:v h264_nvenc -cq:v 35 -rc:v vbr -c:a aac -pix_fmt yuv420p -color_primaries 1 -color_trc 1 -colorspace 1 -movflags +faststart {{OUTPUT}}"
|
||||||
suffix = "h264-vbr35.mp4"
|
suffix = "h264-vbr35.mp4"
|
||||||
|
|
||||||
[[encoders]]
|
[[encoders]]
|
||||||
name = "AV1 Full CRF38"
|
name = "AV1 Full CRF38"
|
||||||
cmd = "ffmpeg -i {{INPUT}} -c:v libsvtav1 -crf 38 -c:a aac -pix_fmt yuv420p -color_primaries 1 -color_trc 1 -colorspace 1 -movflags +faststart {{OUTPUT}}"
|
cmd = "ffmpeg -i {{INPUT}} -nostdin -c:v libsvtav1 -crf 38 -c:a aac -pix_fmt yuv420p -color_primaries 1 -color_trc 1 -colorspace 1 -movflags +faststart {{OUTPUT}}"
|
||||||
suffix = "av1-crf38.mp4"
|
suffix = "av1-crf38.mp4"
|
||||||
|
|
||||||
#[[encoders]]
|
#[[encoders]]
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use std::path::Path;
|
|||||||
use std::process::{Command, Output};
|
use std::process::{Command, Output};
|
||||||
use serde::{Deserialize};
|
use serde::{Deserialize};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
|
use tempdir::TempDir;
|
||||||
use crate::utils::run_cmd;
|
use crate::utils::run_cmd;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
@@ -32,6 +33,28 @@ impl Encoders {
|
|||||||
let content = fs::read_to_string(file)?;
|
let content = fs::read_to_string(file)?;
|
||||||
Ok(toml::from_str(&*content)?)
|
Ok(toml::from_str(&*content)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn exec_all(&self, orig: &str, out: &Path) -> Result<()> {
|
||||||
|
for enc in self.encoders {
|
||||||
|
let enc_out = out.with_extension(enc.suffix);
|
||||||
|
// Skip if encoded video already exists
|
||||||
|
if enc_out.exists() { continue }
|
||||||
|
|
||||||
|
// 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")?)?;
|
||||||
|
|
||||||
|
// Copy results
|
||||||
|
fs::copy(tmp_out, enc_out)?;
|
||||||
|
|
||||||
|
// Cleanup tmp
|
||||||
|
tmp_dir.close()?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user