From c50584b8d150a1abefd749c56dc3cbab9e773c03 Mon Sep 17 00:00:00 2001 From: Alex Butler Date: Sun, 22 Dec 2024 15:22:03 +0000 Subject: [PATCH] Add defaults for mpeg2video encoder --- CHANGELOG.md | 1 + src/command/args/encode.rs | 8 ++++++++ src/command/crf_search.rs | 13 ++++++++----- src/ffmpeg.rs | 3 ++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4228147..c180497 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased (0.8.1) * Support negative `--preset` args. * Add `--vmaf-fps`: Frame rate override used to analyse both reference & distorted videos. +* mpeg2video: map `--crf` to ffmpeg `-q` and set default crf range to 2-30. # v0.8.0 * crf-search: Tweak 2nd iteration logic that slices the crf range at the 25% or 75% crf point. diff --git a/src/command/args/encode.rs b/src/command/args/encode.rs index ba22638..a3eb6ba 100644 --- a/src/command/args/encode.rs +++ b/src/command/args/encode.rs @@ -341,11 +341,19 @@ impl Encoder { } } + pub fn default_min_crf(&self) -> f32 { + match self.as_str() { + "mpeg2video" => 2.0, + _ => 10.0, + } + } + pub fn default_max_crf(&self) -> f32 { match self.as_str() { "libx264" | "libx265" => 46.0, "librav1e" => 255.0, "av1_vaapi" => 255.0, + "mpeg2video" => 30.0, // Works well for svt-av1 _ => 55.0, } diff --git a/src/command/crf_search.rs b/src/command/crf_search.rs index 7540f2f..e20c1f6 100644 --- a/src/command/crf_search.rs +++ b/src/command/crf_search.rs @@ -26,7 +26,6 @@ use std::{ }; const BAR_LEN: u64 = 1024 * 1024 * 1024; -const DEFAULT_MIN_CRF: f32 = 10.0; /// Interpolated binary search using sample-encode to find the best crf /// value delivering min-vmaf & max-encoded-percent. @@ -54,12 +53,14 @@ pub struct Args { pub max_encoded_percent: f32, /// Minimum (highest quality) crf value to try. - #[arg(long, default_value_t = DEFAULT_MIN_CRF)] - pub min_crf: f32, + /// + /// [default: 10, 2 for mpeg2video] + #[arg(long)] + pub min_crf: Option, /// Maximum (lowest quality) crf value to try. /// - /// [default: 55, 46 for x264,x265, 255 for rav1e,av1_vaapi] + /// [default: 55, 46 for x264,x265, 255 for rav1e,av1_vaapi, 30 for mpeg2video] #[arg(long)] pub max_crf: Option, @@ -198,6 +199,8 @@ pub fn run( async_stream::try_stream! { let default_max_crf = args.encoder.default_max_crf(); let max_crf = max_crf.unwrap_or(default_max_crf); + let default_min_crf = args.encoder.default_min_crf(); + let min_crf = min_crf.unwrap_or(default_min_crf); Error::ensure_other(min_crf < max_crf, "Invalid --min-crf & --max-crf")?; // Whether to make the 2nd iteration on the ~20%/~80% crf point instead of the min/max to @@ -208,7 +211,7 @@ pub fn run( // the min/max crf on the 3rd iter. // // If a custom crf range is being used under half the default, this 2nd cut is not needed. - let cut_on_iter2 = (max_crf - min_crf) > (default_max_crf - DEFAULT_MIN_CRF) * 0.5; + let cut_on_iter2 = (max_crf - min_crf) > (default_max_crf - default_min_crf) * 0.5; let crf_increment = crf_increment .unwrap_or_else(|| args.encoder.default_crf_increment()) diff --git a/src/ffmpeg.rs b/src/ffmpeg.rs index 69c7121..5352017 100644 --- a/src/ffmpeg.rs +++ b/src/ffmpeg.rs @@ -204,10 +204,11 @@ impl VCodecSpecific for Arc { } fn crf_arg(&self) -> &str { - // // use crf-like args to support encoders that don't have crf + // use crf-like args to support encoders that don't have crf match &**self { // https://ffmpeg.org//ffmpeg-codecs.html#librav1e "librav1e" => "-qp", + "mpeg2video" => "-q", // https://ffmpeg.org//ffmpeg-codecs.html#VAAPI-encoders e if e.ends_with("_vaapi") => "-q", e if e.ends_with("_nvenc") => "-cq",