fix codec comparison; encode with higher quality for intermediate results
All checks were successful
Trigger quay.io Webhook / run (push) Successful in 5s

This commit is contained in:
Dominic 2024-06-26 12:04:39 +02:00
parent b6fb0fa184
commit 7662150b89
Signed by: msrd0
GPG key ID: AAF7C8430CA3345D
3 changed files with 27 additions and 5 deletions

View file

@ -51,7 +51,7 @@ impl Resolution {
}
pub(crate) fn default_codec(self) -> FfmpegOutputFormat {
if self.width <= 1920 {
if self.width > 1920 {
FfmpegOutputFormat::Av1Opus
} else {
FfmpegOutputFormat::AvcAac

View file

@ -63,8 +63,14 @@ pub(crate) enum FfmpegOutputFormat {
AvcAac
}
pub(crate) enum FfmpegOutputQuality {
Default,
VisuallyLossless
}
pub(crate) struct FfmpegOutput {
pub(crate) format: FfmpegOutputFormat,
pub(crate) quality: FfmpegOutputQuality,
pub(crate) audio_bitrate: Option<u64>,
pub(crate) video_bitrate: Option<u64>,
@ -89,6 +95,7 @@ impl FfmpegOutput {
pub(crate) fn new(format: FfmpegOutputFormat, path: PathBuf) -> Self {
Self {
format,
quality: FfmpegOutputQuality::Default,
audio_bitrate: None,
video_bitrate: None,
@ -117,7 +124,7 @@ impl FfmpegOutput {
self
}
fn append_to_cmd(self, cmd: &mut Command, venc: bool, _aenc: bool, mut vaapi: bool) {
fn append_to_cmd(self, cmd: &mut Command, venc: bool, _aenc: bool, vaapi: bool) {
// select codec and bitrate/crf
if venc {
let vcodec = match (self.format, vaapi) {
@ -133,10 +140,23 @@ impl FfmpegOutput {
if vcodec == "libsvtav1" {
cmd.arg("-svtav1-params").arg("fast-decode=1");
cmd.arg("-preset").arg("7");
cmd.arg("-crf").arg("28");
cmd.arg("-crf").arg(match self.quality {
FfmpegOutputQuality::Default => "28",
FfmpegOutputQuality::VisuallyLossless => "18"
});
} else if vcodec == "h264" {
cmd.arg("-preset").arg("slow");
cmd.arg("-crf").arg("21");
match self.quality {
FfmpegOutputQuality::Default => {
cmd.arg("-preset").arg("slow");
cmd.arg("-crf").arg("21");
},
FfmpegOutputQuality::VisuallyLossless => {
// the quality is not impacted by speed, only the bitrate, and
// for this setting we don't really care about bitrate
cmd.arg("-preset").arg("veryfast");
cmd.arg("-crf").arg("17");
}
}
} else if let Some(bv) = self.video_bitrate {
cmd.arg("-b:v").arg(bv.to_string());
}

View file

@ -15,6 +15,7 @@ use crate::{
use anyhow::{bail, Context};
use camino::{Utf8Path as Path, Utf8PathBuf as PathBuf};
use console::style;
use ffmpeg::FfmpegOutputQuality;
use std::{
borrow::Cow,
collections::VecDeque,
@ -377,6 +378,7 @@ impl<'a> Renderer<'a> {
let output = self.video_file_output();
let mut ffmpeg = Ffmpeg::new(FfmpegOutput {
quality: FfmpegOutputQuality::VisuallyLossless,
video_bitrate: Some(source_res.bitrate() * 3),
..FfmpegOutput::new(self.format, output.clone())
});