[+] Encoder::exec_all

This commit is contained in:
Azalea Gui
2023-02-24 12:22:35 -05:00
parent b39f28fab6
commit ee67670a89
2 changed files with 25 additions and 2 deletions
+2 -2
View File
@@ -2,12 +2,12 @@ processes = 2
[[encoders]]
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"
[[encoders]]
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"
#[[encoders]]
+23
View File
@@ -3,6 +3,7 @@ use std::path::Path;
use std::process::{Command, Output};
use serde::{Deserialize};
use anyhow::{Context, Result};
use tempdir::TempDir;
use crate::utils::run_cmd;
#[derive(Deserialize, Debug)]
@@ -32,6 +33,28 @@ impl Encoders {
let content = fs::read_to_string(file)?;
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(())
}
}