support rescaling

This commit is contained in:
Dominic 2023-11-03 10:02:30 +01:00
parent 268c4b3af7
commit feb8596bfc
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 125 additions and 46 deletions

View file

@ -261,18 +261,17 @@ impl<'a> Renderer<'a> {
Ok(())
}
fn video_mp4_res(&self, res: Resolution) -> PathBuf {
self.target
.join(format!("{}-{}p.mp4", self.slug, res.height()))
}
pub(crate) fn video_mp4(&self, project: &Project) -> PathBuf {
self.video_mp4_res(project.source.metadata.as_ref().unwrap().source_res)
}
pub(crate) fn render(&self, project: &mut Project) -> anyhow::Result<PathBuf> {
let mut output = self.target.join(format!(
"{}-{}p.mp4",
self.slug,
project
.source
.metadata
.as_ref()
.unwrap()
.source_res
.height()
));
let output = self.video_mp4(project);
let mut ffmpeg = Ffmpeg::new(output.clone());
// add all of our inputs
@ -435,4 +434,37 @@ impl<'a> Renderer<'a> {
Ok(output)
}
pub fn rescale(&self, res: Resolution, project: &Project) -> anyhow::Result<PathBuf> {
let input = self.video_mp4(project);
let output = self.video_mp4_res(res);
println!("\x1B[1m ==> Rescaling to {}p\x1B[0m", res.height());
let mut ffmpeg = cmd();
ffmpeg.arg("ffmpeg").arg("-hide_banner");
// TODO do we just always want hwaccel?
ffmpeg
.arg("-hwaccel")
.arg("vaapi")
.arg("-hwaccel_device")
.arg("/dev/dri/renderD128")
.arg("-hwaccel_output_format")
.arg("vaapi");
ffmpeg.arg("-i").arg(input);
ffmpeg.arg("-vf").arg(format!(
"scale_vaapi=w={}:h={}",
res.width(),
res.height()
));
ffmpeg.arg("-c:a").arg("copy").arg("-c:v").arg("h264_vaapi");
ffmpeg.arg("-b:v").arg(res.bitrate());
ffmpeg.arg(&output);
let status = ffmpeg.status()?;
if status.success() {
Ok(output)
} else {
bail!("ffmpeg failed with exit code {:?}", status.code())
}
}
}