Skip to content
Snippets Groups Projects
Unverified Commit 24ea4ebe authored by Dominic Meiser's avatar Dominic Meiser
Browse files

make transcoding optional

parent 371071ca
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ use std::{
fmt::Display,
fs,
io::{self, BufRead as _, Write},
str::FromStr,
sync::RwLock
};
......@@ -27,20 +28,27 @@ static MEM_LIMIT: RwLock<String> = RwLock::new(String::new());
#[derive(Debug, Parser)]
struct Args {
/// The root directory of the project. It should contain the raw video file(s).
#[clap(short = 'C', long, default_value = ".")]
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,
/// The memory limit for external tools like ffmpeg.
#[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 {
($($res:ident: $width:literal x $height:literal at $bitrate:literal),+) => {
#[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 {
$(
#[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
if let Some(lowest_res) = args.transcode {
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;
}
if !project.progress.transcoded.contains(&res) {
......@@ -288,6 +310,7 @@ fn main() {
.unwrap();
}
}
}
println!("\x1B[1m ==> DONE :)\x1B[0m");
println!(" Videos:");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment