From 5e1f5e882955e679490e4aacba7b59f7f1691574 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 29 Jun 2024 11:21:06 +0200 Subject: [PATCH 1/4] add readme [skip ci] no need --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..d457a56 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +**ACHTUNG!** This repository might be mirrored at different places, but the main repository is and remains at [msrd0.dev/msrd0/render_video](https://msrd0.dev/msrd0/render_video). Please redirect all issues and pull requests there. + +# render_video + +This "script" is an extremely fancy wrapper around ffmpeg to cut/render videos for the [VideoAG](https://video.fsmpi.rwth-aachen.de) of the [Fachschaft I/1 der RWTH Aachen University](https://fsmpi.rwth-aachen.de). + +You can find a ready-to-use docker image at [`quay.io/msrd0/render_video`](https://quay.io/msrd0/render_video). + +## Features + + - **Extract a single audio channel from stereo recording.** We use that with one of our cameras that supports plugging a lavalier microphone (mono source) into one channel of the stereo recording, and using the camera microphone (mono source) for the other channel of the stereo recording. + - **Cut away before/after the lecture.** We don't hit the start record button the exact time that the lecture starts, and don't hit the stop button exactly when the lecture ends, so we need to cut away those unwanted bits. + - **Fast-forward through _Tafelwischpausen_.** Sometimes docents still use blackboards and need to wipe those, which can be fast-forwarded by this tool. + - **Overlay questions from the audience.** Sometimes people in the audience have questions, and those are usually poorly understood on the lavalier microphones. Therefore you can subtitle these using the other microphones in the room that don't make it into the final video and have those overlayed. + - **Add intro and outro.** We add intro and outro slides at the start/end at all lectures, which this tool can do for you. + - **Add our logo watermark.** We add a logo watermark in the bottom right corner of all videos, which this tool can do for you. + - **Rescale to lower resolutions.** We usually published videos at different resolutions, and this tool can rescale your video for all resolutions you want. From d5bb7a4bdcb488c3b2ed2ba8a5acac1f3ee21ba1 Mon Sep 17 00:00:00 2001 From: Dominic Date: Mon, 8 Jul 2024 13:18:26 +0200 Subject: [PATCH 2/4] only use vaapi when feature is enabled --- Cargo.toml | 1 + src/render/ffmpeg.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d73faad..e405c72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,3 +24,4 @@ toml = { package = "basic-toml", version = "0.1.4" } [features] default = ["mem_limit"] mem_limit = [] +vaapi = [] diff --git a/src/render/ffmpeg.rs b/src/render/ffmpeg.rs index 8bcc37b..30b3d79 100644 --- a/src/render/ffmpeg.rs +++ b/src/render/ffmpeg.rs @@ -322,7 +322,7 @@ impl Ffmpeg { // initialise a vaapi device if one exists let vaapi_device: PathBuf = "/dev/dri/renderD128".into(); - let vaapi = vaapi_device.exists(); + let vaapi = cfg!(feature = "vaapi") && vaapi_device.exists(); if vaapi && venc { if vdec { cmd.arg("-hwaccel").arg("vaapi"); From dd5847da484532b229d8c0096ed7bd9bb1bf6724 Mon Sep 17 00:00:00 2001 From: Dominic Date: Fri, 17 Jan 2025 17:55:58 +0100 Subject: [PATCH 3/4] support custom resolutions --- src/project.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/project.rs b/src/project.rs index 93d7a45..82eba5d 100644 --- a/src/project.rs +++ b/src/project.rs @@ -94,7 +94,17 @@ impl FromStr for Resolution { "1080p" | "fhd" | "fullhd" => Self(1920, 1080), "1440p" | "wqhd" => Self(2560, 1440), "2160p" | "4k" | "uhd" => Self(3840, 2160), - _ => anyhow::bail!("Unknown Resolution: {s:?}") + lower => { + let mut parts = lower.split('x'); + match ( + parts.next().map(|width| width.parse()), + parts.next().map(|height| height.parse()), + parts.next() + ) { + (Some(Ok(width)), Some(Ok(height)), None) => Self(width, height), + _ => anyhow::bail!("Unknown Resolution: {s:?}") + } + } }) } } @@ -204,3 +214,16 @@ pub struct ProjectProgress { #[serde(default)] pub transcoded: BTreeSet } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_custom_resolution() { + assert_eq!( + Resolution(1920, 1334), + "1920x1334".parse::().unwrap() + ); + } +} From 031b03e7e40779a5eaad7f40726458e6eb84d231 Mon Sep 17 00:00:00 2001 From: Dominic Date: Sat, 3 May 2025 00:52:43 +0200 Subject: [PATCH 4/4] always transcode for the highest/lowest resolutions --- src/main.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index a0b32e4..7d0a56b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,7 +12,7 @@ use render_video::{ render::Renderer, time::parse_date }; -use std::fs; +use std::{collections::BTreeSet, fs}; #[derive(Debug, Parser)] struct Args { @@ -215,13 +215,17 @@ fn main() { // rescale the video if let Some(lowest_res) = args.transcode.or(preset.transcode) { - for res in Resolution::STANDARD_RESOLUTIONS.into_iter().rev() { - if res > project.source.metadata.as_ref().unwrap().source_res - || res > args.transcode_start.unwrap_or(preset.transcode_start) - || res < lowest_res - { - continue; - } + let highest_res = args.transcode_start.unwrap_or(preset.transcode_start); + let source_res = project.source.metadata.as_ref().unwrap().source_res; + let mut resolutions = Resolution::STANDARD_RESOLUTIONS + .into_iter() + .collect::>(); + resolutions.retain(|res| { + *res <= source_res && *res <= highest_res && *res >= lowest_res + }); + resolutions.insert(highest_res); + resolutions.insert(lowest_res); + for res in resolutions { if !project.progress.transcoded.contains(&res) { videos.push(renderer.rescale(&project.lecture, res).unwrap()); project.progress.transcoded.insert(res);