diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bc1b46..a09cfd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased (0.9.2) +* Log crf results, instead of printing, if stderr is not a terminal. + # v0.9.1 * Fix xpsnr inf score parsing. * Fix xpsnr reference vfilter usage. diff --git a/Cargo.lock b/Cargo.lock index dfd04c0..0d362ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -99,9 +99,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.95" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "6b964d184e89d9b6b67dd2715bc8e74cf3107fb2b529990c90cf517326150bf4" [[package]] name = "arrayref" @@ -172,9 +172,9 @@ checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "blake3" -version = "1.5.5" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8ee0c1824c4dea5b5f81736aff91bae041d2c07ee1192bec91054e10e3e601e" +checksum = "675f87afced0413c9bb02843499dbbd3882a237645883f71a2b59644a6d2f753" dependencies = [ "arrayref", "arrayvec", @@ -197,15 +197,15 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "325918d6fe32f23b19878fe4b34794ae41fc19ddbe53b10571a4874d44ffd39b" +checksum = "f61dac84819c6588b558454b194026eb1f09c293b9036ae9b159e74e73ab6cf9" [[package]] name = "cc" -version = "1.2.11" +version = "1.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4730490333d58093109dc02c23174c3f4d490998c3fed3cc8e82d57afedb9cf" +checksum = "be714c154be609ec7f5dad223a33bf1482fff90472de28f7362806e6d4832b8c" dependencies = [ "shlex", ] @@ -218,9 +218,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.5.27" +version = "4.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" +checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767" dependencies = [ "clap_builder", "clap_derive", @@ -238,9 +238,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.27" +version = "4.5.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" +checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863" dependencies = [ "anstream", "anstyle", @@ -251,18 +251,18 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.5.44" +version = "4.5.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "375f9d8255adeeedd51053574fd8d4ba875ea5fa558e86617b07f09f1680c8b6" +checksum = "f5c5508ea23c5366f77e53f5a0070e5a84e51687ec3ef9e0464c86dc8d13ce98" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.5.24" +version = "4.5.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" +checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed" dependencies = [ "heck", "proc-macro2", @@ -598,9 +598,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.169" +version = "0.2.170" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" [[package]] name = "libredox" @@ -630,9 +630,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.25" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" +checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" [[package]] name = "memchr" @@ -642,9 +642,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "miniz_oxide" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8402cab7aefae129c6977bb0ff1b8fd9a04eb5b51efc50a70bea51cda0c7924" +checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" dependencies = [ "adler2", ] @@ -683,9 +683,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.20.2" +version = "1.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" [[package]] name = "option-ext" @@ -732,9 +732,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "portable-atomic" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280dc24453071f1b63954171985a0b0d30058d287960968b9b2aca264c8d4ee6" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" [[package]] name = "powerfmt" @@ -813,18 +813,18 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.217" +version = "1.0.218" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.217" +version = "1.0.218" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b" dependencies = [ "proc-macro2", "quote", @@ -833,9 +833,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" +checksum = "44f86c3acccc9c65b153fe1b85a3be07fe5515274ec9f0653b4a0875731c72a6" dependencies = [ "itoa", "memchr", @@ -891,9 +891,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.13.2" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd" [[package]] name = "strsim" @@ -1040,9 +1040,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.16" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a210d160f08b701c8721ba1c726c11662f877ea6b7094007e1ca9a1041945034" +checksum = "00e2473a93778eb0bad35909dff6a10d28e63f792f16ed15e404fca9d5eeedbe" [[package]] name = "unicode-width" diff --git a/Cargo.toml b/Cargo.toml index 2f9bc8a..4568c1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "ab-av1" version = "0.9.1" authors = ["Alex Butler "] -edition = "2021" +edition = "2024" description = "AV1 encoding with fast VMAF sampling" repository = "https://github.com/alexheretic/ab-av1" keywords = ["av1", "vmaf"] diff --git a/src/command/auto_encode.rs b/src/command/auto_encode.rs index 398e83d..0edc24b 100644 --- a/src/command/auto_encode.rs +++ b/src/command/auto_encode.rs @@ -1,9 +1,8 @@ use crate::{ command::{ - args, crf_search, + PROGRESS_CHARS, args, crf_search, encode::{self, default_output_name}, sample_encode::{self, Work}, - PROGRESS_CHARS, }, console_ext::style, ffprobe, @@ -39,8 +38,7 @@ pub struct Args { } pub async fn auto_encode(Args { mut search, encode }: Args) -> anyhow::Result<()> { - const SPINNER_RUNNING: &str = - "{spinner:.cyan.bold} {elapsed_precise:.bold} {prefix} {wide_bar:.cyan/blue} ({msg}eta {eta})"; + const SPINNER_RUNNING: &str = "{spinner:.cyan.bold} {elapsed_precise:.bold} {prefix} {wide_bar:.cyan/blue} ({msg}eta {eta})"; const SPINNER_FINISHED: &str = "{spinner:.cyan.bold} {elapsed_precise:.bold} {prefix} {wide_bar:.cyan/blue} ({msg})"; diff --git a/src/command/crf_search.rs b/src/command/crf_search.rs index db2dc65..7a364a1 100644 --- a/src/command/crf_search.rs +++ b/src/command/crf_search.rs @@ -4,9 +4,8 @@ pub use err::Error; use crate::{ command::{ - args, + PROGRESS_CHARS, args, sample_encode::{self, Work}, - PROGRESS_CHARS, }, console_ext::style, ffprobe::{self, Ffprobe}, @@ -18,12 +17,7 @@ use console::style; use futures_util::{Stream, StreamExt}; use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressStyle}; use log::info; -use std::{ - io::{self, IsTerminal}, - pin::pin, - sync::Arc, - time::Duration, -}; +use std::{io::IsTerminal, pin::pin, sync::Arc, time::Duration}; const BAR_LEN: u64 = 1024 * 1024 * 1024; const DEFAULT_MIN_VMAF: f32 = 95.0; @@ -370,6 +364,18 @@ impl Sample { } pub fn print_attempt(&self, bar: &ProgressBar, min_score: f32, max_encoded_percent: f32) { + if bar.is_hidden() { + info!( + "crf {} {} {:.2} ({:.0}%){}", + TerseF32(self.crf()), + self.enc.score_kind, + self.enc.score, + self.enc.encode_percent, + if self.enc.from_cache { " (cache)" } else { "" } + ); + return; + } + let crf_label = style("- crf").dim(); let mut crf = style(TerseF32(self.crf())); let vmaf_label = style(self.enc.score_kind).dim(); @@ -391,13 +397,9 @@ impl Sample { percent = percent.red().bright(); } - let msg = - format!("{crf_label} {crf} {vmaf_label} {vmaf:.2} {open}{percent}{close}{cache_msg}"); - if io::stderr().is_terminal() { - bar.println(msg); - } else { - eprintln!("{msg}"); - } + bar.println(format!( + "{crf_label} {crf} {vmaf_label} {vmaf:.2} {open}{percent}{close}{cache_msg}" + )); } } diff --git a/src/command/encode.rs b/src/command/encode.rs index 88d8382..16bc67b 100644 --- a/src/command/encode.rs +++ b/src/command/encode.rs @@ -1,7 +1,7 @@ use crate::{ command::{ + PROGRESS_CHARS, SmallDuration, args::{self, Encoder}, - SmallDuration, PROGRESS_CHARS, }, console_ext::style, ffmpeg, diff --git a/src/command/sample_encode.rs b/src/command/sample_encode.rs index 91a37dc..88bc3e4 100644 --- a/src/command/sample_encode.rs +++ b/src/command/sample_encode.rs @@ -2,9 +2,9 @@ mod cache; use crate::{ command::{ + PROGRESS_CHARS, SmallDuration, args::{self, PixelFormat}, sample_encode::cache::ScoringInfo, - SmallDuration, PROGRESS_CHARS, }, console_ext::style, ffmpeg::{self, FfmpegEncodeArgs}, @@ -15,7 +15,7 @@ use crate::{ vmaf::{self, VmafOut}, xpsnr::{self, XpsnrOut}, }; -use anyhow::{ensure, Context}; +use anyhow::{Context, ensure}; use clap::{ArgAction, Parser}; use console::style; use futures_util::Stream; diff --git a/src/command/vmaf.rs b/src/command/vmaf.rs index 7e5796d..009549c 100644 --- a/src/command/vmaf.rs +++ b/src/command/vmaf.rs @@ -1,7 +1,7 @@ use crate::{ command::{ - args::{self, PixelFormat}, PROGRESS_CHARS, + args::{self, PixelFormat}, }, ffprobe, log::ProgressLogger, diff --git a/src/command/xpsnr.rs b/src/command/xpsnr.rs index 33ba95f..e8b27df 100644 --- a/src/command/xpsnr.rs +++ b/src/command/xpsnr.rs @@ -1,5 +1,5 @@ use crate::{ - command::{args, PROGRESS_CHARS}, + command::{PROGRESS_CHARS, args}, ffprobe, log::ProgressLogger, process::FfmpegOut, diff --git a/src/ffprobe.rs b/src/ffprobe.rs index ee78826..28f48d8 100644 --- a/src/ffprobe.rs +++ b/src/ffprobe.rs @@ -1,6 +1,6 @@ //! ffprobe logic use crate::command::args::PixelFormat; -use anyhow::{anyhow, Context}; +use anyhow::{Context, anyhow}; use std::{fmt, fs::File, io::Read, path::Path, time::Duration}; pub struct Ffprobe { @@ -53,7 +53,7 @@ pub fn probe(input: &Path) -> Ffprobe { resolution: None, is_image: false, pix_fmt: None, - } + }; } }; diff --git a/src/log.rs b/src/log.rs index 1e3f80c..8a1a219 100644 --- a/src/log.rs +++ b/src/log.rs @@ -1,5 +1,5 @@ use indicatif::HumanDuration; -use log::{info, log_enabled, Level}; +use log::{Level, info, log_enabled}; use std::time::{Duration, Instant}; /// Struct that info logs progress messages on a stream action like encoding. diff --git a/src/main.rs b/src/main.rs index bfaff34..092320b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ use ::log::LevelFilter; use anyhow::anyhow; use clap::Parser; use futures_util::FutureExt; -use std::{env, io::IsTerminal}; +use std::io::IsTerminal; use tokio::signal; #[derive(Parser)] @@ -31,21 +31,21 @@ enum Command { #[tokio::main(flavor = "current_thread")] async fn main() { - let stderr_term = std::io::stderr().is_terminal(); - if !stderr_term && env::var_os("RUST_LOG").is_none() { - env::set_var("RUST_LOG", "ab_av1=info"); - } env_logger::builder() - .filter_level(LevelFilter::Off) + .filter_module( + "ab_av1", + match std::io::stderr().is_terminal() { + true => LevelFilter::Off, + false => LevelFilter::Info, + }, + ) .parse_default_env() .init(); let action = Command::parse(); - let keep = action.keep_temp_files(); let local = tokio::task::LocalSet::new(); - let command = local.run_until(match action { Command::SampleEncode(args) => command::sample_encode(args).boxed_local(), Command::Vmaf(args) => command::vmaf(args).boxed_local(), diff --git a/src/sample.rs b/src/sample.rs index e28a4f9..74c9340 100644 --- a/src/sample.rs +++ b/src/sample.rs @@ -1,6 +1,6 @@ //! ffmpeg logic use crate::{ - process::{ensure_success, CommandExt}, + process::{CommandExt, ensure_success}, temporary::{self, TempKind}, }; use anyhow::Context; diff --git a/src/vmaf.rs b/src/vmaf.rs index 6ee1e31..2d7bc80 100644 --- a/src/vmaf.rs +++ b/src/vmaf.rs @@ -1,5 +1,5 @@ //! vmaf logic -use crate::process::{cmd_err, exit_ok_stderr, Chunks, CommandExt, FfmpegOut}; +use crate::process::{Chunks, CommandExt, FfmpegOut, cmd_err, exit_ok_stderr}; use anyhow::Context; use log::{debug, info}; use std::{path::Path, process::Stdio}; @@ -13,7 +13,7 @@ pub fn run( distorted: &Path, filter_complex: &str, fps: Option, -) -> anyhow::Result> { +) -> anyhow::Result + use<>> { info!( "vmaf {} vs reference {}", distorted.file_name().and_then(|n| n.to_str()).unwrap_or(""), diff --git a/src/xpsnr.rs b/src/xpsnr.rs index 4a8ad01..6e549fa 100644 --- a/src/xpsnr.rs +++ b/src/xpsnr.rs @@ -1,5 +1,5 @@ //! xpsnr logic -use crate::process::{cmd_err, exit_ok_stderr, Chunks, CommandExt, FfmpegOut}; +use crate::process::{Chunks, CommandExt, FfmpegOut, cmd_err, exit_ok_stderr}; use anyhow::Context; use log::{debug, info}; use std::{path::Path, process::Stdio}; @@ -13,7 +13,7 @@ pub fn run( distorted: &Path, filter_complex: &str, fps: Option, -) -> anyhow::Result> { +) -> anyhow::Result + use<>> { info!( "xpsnr {} vs reference {}", distorted.file_name().and_then(|n| n.to_str()).unwrap_or(""),