only use av1 for >fhd videos

This commit is contained in:
Dominic 2024-01-15 18:50:15 +01:00
parent 3aeb9dd8be
commit fead583ce9
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 29 additions and 6 deletions

View file

@ -53,6 +53,7 @@ impl FfmpegInput {
}
}
#[derive(Clone, Copy)]
pub(crate) enum FfmpegOutputFormat {
/// AV1 / FLAC
Av1Flac,

View file

@ -114,20 +114,23 @@ pub(crate) struct Renderer<'a> {
/// The slug (i.e. 23ws-malo2-231016).
slug: String,
/// The target directory.
target: PathBuf
target: PathBuf,
/// The format to use for intermediate products
format: FfmpegOutputFormat
}
fn svg2mkv(
meta: &ProjectSourceMetadata,
svg: PathBuf,
mkv: PathBuf,
format: FfmpegOutputFormat,
duration: Time
) -> anyhow::Result<()> {
let mut ffmpeg = Ffmpeg::new(FfmpegOutput {
duration: Some(duration),
time_base: Some(meta.source_tbn),
fps_mode_vfr: true,
..FfmpegOutput::new(FfmpegOutputFormat::Av1Flac, mkv)
..FfmpegOutput::new(format, mkv)
});
ffmpeg.add_input(FfmpegInput {
loop_input: true,
@ -170,10 +173,29 @@ impl<'a> Renderer<'a> {
let target = directory.join(&slug);
fs::create_dir_all(&target)?;
let first: PathBuf = directory.join(
project
.source
.files
.first()
.context("No source files present")?
);
let height: u32 = ffprobe_video("stream=height", &first)?
.split('\n')
.next()
.unwrap()
.parse()?;
let format = if height <= 1080 {
FfmpegOutputFormat::AvcAac
} else {
FfmpegOutputFormat::Av1Flac
};
Ok(Self {
directory,
slug,
target
target,
format
})
}
@ -244,7 +266,7 @@ impl<'a> Renderer<'a> {
.into_bytes()
)?;
let intro_mkv = self.intro_mkv();
svg2mkv(metadata, intro_svg, intro_mkv, INTRO_LEN)?;
svg2mkv(metadata, intro_svg, intro_mkv, self.format, INTRO_LEN)?;
// render outro to svg then mp4
let outro_svg = self.target.join("outro.svg");
@ -253,7 +275,7 @@ impl<'a> Renderer<'a> {
outro(source_res).to_string_pretty().into_bytes()
)?;
let outro_mkv = self.outro_mkv();
svg2mkv(metadata, outro_svg, outro_mkv, OUTRO_LEN)?;
svg2mkv(metadata, outro_svg, outro_mkv, self.format, OUTRO_LEN)?;
// copy logo then render to png
let logo_svg = self.target.join("logo.svg");
@ -305,7 +327,7 @@ impl<'a> Renderer<'a> {
let output = self.video_file_output();
let mut ffmpeg = Ffmpeg::new(FfmpegOutput {
video_bitrate: Some(source_res.bitrate() * 3),
..FfmpegOutput::new(FfmpegOutputFormat::Av1Flac, output.clone())
..FfmpegOutput::new(self.format, output.clone())
});
// add all of our inputs