also preprocess the assets

This commit is contained in:
Dominic 2023-10-30 17:55:53 +01:00
parent 986b51f0c3
commit 56c6fb6be2
Signed by: msrd0
GPG key ID: DCC8C247452E98F9

View file

@ -131,6 +131,20 @@ fn svg2mp4(svg: PathBuf, mp4: PathBuf, duration: Time) -> anyhow::Result<()> {
ffmpeg.run() ffmpeg.run()
} }
fn svg2png(svg: &Path, png: &Path, size: usize) -> anyhow::Result<()> {
let mut cmd = cmd();
let size = size.to_string();
cmd.arg("inkscape").arg("-w").arg(&size).arg("-h").arg(&size);
cmd.arg(svg).arg("-o").arg(png);
let status = cmd.status()?;
if status.success() {
Ok(())
} else {
bail!("inkscape failed with exit code {:?}", status.code())
}
}
impl<'a> Renderer<'a> { impl<'a> Renderer<'a> {
pub(crate) fn new(directory: &'a Path, project: &Project) -> anyhow::Result<Self> { pub(crate) fn new(directory: &'a Path, project: &Project) -> anyhow::Result<Self> {
let slug = format!( let slug = format!(
@ -150,20 +164,6 @@ impl<'a> Renderer<'a> {
pub(crate) fn preprocess(&self, project: &mut Project) -> anyhow::Result<()> { pub(crate) fn preprocess(&self, project: &mut Project) -> anyhow::Result<()> {
assert!(!project.progress.preprocessed); assert!(!project.progress.preprocessed);
let logo = self.target.join("logo.svg");
fs::write(
&logo,
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/logo.svg"))
)?;
let fastforward = self.target.join("fastforward.svg");
fs::write(
&fastforward,
include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/fastforward.svg"
))
)?;
let recording_txt = self.target.join("recording.txt"); let recording_txt = self.target.join("recording.txt");
let mut file = File::create(&recording_txt)?; let mut file = File::create(&recording_txt)?;
for filename in &project.source.files { for filename in &project.source.files {
@ -201,6 +201,7 @@ impl<'a> Renderer<'a> {
source_sample_rate source_sample_rate
}); });
// render intro to svg then mp4
let intro_svg = self.target.join("intro.svg"); let intro_svg = self.target.join("intro.svg");
fs::write( fs::write(
&intro_svg, &intro_svg,
@ -214,6 +215,7 @@ impl<'a> Renderer<'a> {
micros: 0 micros: 0
})?; })?;
// render outro to svg then mp4
let outro_svg = self.target.join("outro.svg"); let outro_svg = self.target.join("outro.svg");
fs::write( fs::write(
&outro_svg, &outro_svg,
@ -225,6 +227,27 @@ impl<'a> Renderer<'a> {
micros: 0 micros: 0
}); });
// copy logo then render to png
let logo_svg = self.target.join("logo.svg");
fs::write(
&logo_svg,
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/assets/logo.svg"))
)?;
let logo_png = self.target.join("logo.png");
svg2png(&logo_svg, &logo_png, 150 * 1920 / source_res.width())?;
// copy fastforward then render to png
let fastforward_svg = self.target.join("fastforward.svg");
fs::write(
&fastforward_svg,
include_bytes!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/assets/fastforward.svg"
))
)?;
let fastforward_png = self.target.join("fastforward.png");
svg2png(&fastforward_svg, &fastforward_png, 128 * 1920 / source_res.width())?;
Ok(()) Ok(())
} }
} }