make transcoding optional

This commit is contained in:
Dominic 2023-11-14 10:36:12 +01:00
parent 371071ca47
commit 24ea4ebe07
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -20,6 +20,7 @@ use std::{
fmt::Display, fmt::Display,
fs, fs,
io::{self, BufRead as _, Write}, io::{self, BufRead as _, Write},
str::FromStr,
sync::RwLock sync::RwLock
}; };
@ -27,20 +28,27 @@ static MEM_LIMIT: RwLock<String> = RwLock::new(String::new());
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct Args { struct Args {
/// The root directory of the project. It should contain the raw video file(s).
#[clap(short = 'C', long, default_value = ".")] #[clap(short = 'C', long, default_value = ".")]
directory: PathBuf, directory: PathBuf,
#[clap(short = 'c', long, default_value = "23ws-malo")] /// The slug of the course, e.g. "23ws-malo2".
#[clap(short = 'c', long, default_value = "23ws-malo2")]
course: String, course: String,
/// The memory limit for external tools like ffmpeg.
#[clap(short, long, default_value = "8G")] #[clap(short, long, default_value = "8G")]
mem_limit: String mem_limit: String,
/// Transcode the final video clip down to the minimum resolution specified.
#[clap(short, long)]
transcode: Option<Resolution>
} }
macro_rules! resolutions { macro_rules! resolutions {
($($res:ident: $width:literal x $height:literal at $bitrate:literal),+) => { ($($res:ident: $width:literal x $height:literal at $bitrate:literal),+) => {
#[allow(non_camel_case_types, clippy::upper_case_acronyms)] #[allow(non_camel_case_types, clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
enum Resolution { enum Resolution {
$( $(
#[doc = concat!(stringify!($width), "x", stringify!($height))] #[doc = concat!(stringify!($width), "x", stringify!($height))]
@ -77,6 +85,17 @@ macro_rules! resolutions {
} }
} }
} }
impl FromStr for Resolution {
type Err = anyhow::Error;
fn from_str(s: &str) -> anyhow::Result<Self> {
Ok(match s {
$(concat!(stringify!($height), "p") => Self::$res,)+
_ => anyhow::bail!("Unknown Resolution: {s:?}")
})
}
}
} }
} }
@ -275,8 +294,11 @@ fn main() {
}); });
// rescale the video // rescale the video
if let Some(lowest_res) = args.transcode {
for res in Resolution::values().into_iter().rev() { for res in Resolution::values().into_iter().rev() {
if res >= project.source.metadata.as_ref().unwrap().source_res { if res >= project.source.metadata.as_ref().unwrap().source_res
|| res < lowest_res
{
continue; continue;
} }
if !project.progress.transcoded.contains(&res) { if !project.progress.transcoded.contains(&res) {
@ -288,6 +310,7 @@ fn main() {
.unwrap(); .unwrap();
} }
} }
}
println!("\x1B[1m ==> DONE :)\x1B[0m"); println!("\x1B[1m ==> DONE :)\x1B[0m");
println!(" Videos:"); println!(" Videos:");