Skip to content

Commit

Permalink
Log crf results, instead of printing, if stderr is not a terminal
Browse files Browse the repository at this point in the history
edition 2024
rm env::set_var usage
  • Loading branch information
alexheretic committed Feb 28, 2025
1 parent 88f59d5 commit 100e8df
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 77 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
72 changes: 36 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "ab-av1"
version = "0.9.1"
authors = ["Alex Butler <[email protected]>"]
edition = "2021"
edition = "2024"
description = "AV1 encoding with fast VMAF sampling"
repository = "https://github.com/alexheretic/ab-av1"
keywords = ["av1", "vmaf"]
Expand Down
6 changes: 2 additions & 4 deletions src/command/auto_encode.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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})";

Expand Down
32 changes: 17 additions & 15 deletions src/command/crf_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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}"
));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/command/encode.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
command::{
PROGRESS_CHARS, SmallDuration,
args::{self, Encoder},
SmallDuration, PROGRESS_CHARS,
},
console_ext::style,
ffmpeg,
Expand Down
4 changes: 2 additions & 2 deletions src/command/sample_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/command/vmaf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
command::{
args::{self, PixelFormat},
PROGRESS_CHARS,
args::{self, PixelFormat},
},
ffprobe,
log::ProgressLogger,
Expand Down
2 changes: 1 addition & 1 deletion src/command/xpsnr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
command::{args, PROGRESS_CHARS},
command::{PROGRESS_CHARS, args},
ffprobe,
log::ProgressLogger,
process::FfmpegOut,
Expand Down
4 changes: 2 additions & 2 deletions src/ffprobe.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -53,7 +53,7 @@ pub fn probe(input: &Path) -> Ffprobe {
resolution: None,
is_image: false,
pix_fmt: None,
}
};
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/log.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading

0 comments on commit 100e8df

Please sign in to comment.