mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-18 14:48:34 +01:00
feat(cli): a measure command and its schema
This commit is contained in:
1 parent
fdb7112373
commit
9e38ce17c1
4 files changed
+142
No files matched your search
@@ -24,6 +24,7 @@ use super::envelope::Envelope;
|
||||
use super::framediff::FrameDiffData;
|
||||
use super::history::HistoryData;
|
||||
use super::logq::LogqData;
|
||||
use super::measure::MeasureData;
|
||||
use super::motion::MotionData;
|
||||
use super::overview::OverviewData;
|
||||
use super::search::SearchData;
|
||||
@@ -129,6 +130,11 @@ pub const ALL: &[Entry] = &[
|
||||
about: "`blank`: stretches where a region was blank (one colour) or frozen",
|
||||
schema: of::<BlankData>,
|
||||
},
|
||||
Entry {
|
||||
name: "measure/1",
|
||||
about: "`measure`: mean or peak brightness or drawn width of a region, on a fixed-rate timeline",
|
||||
schema: of::<MeasureData>,
|
||||
},
|
||||
Entry {
|
||||
name: "compare/1",
|
||||
about: "`compare`: two recordings side by side with the difference of each measure",
|
||||
|
||||
@@ -61,6 +61,7 @@ pub use video::BlankArgs;
|
||||
pub use video::ChangesArgs;
|
||||
pub use video::CompareArgs;
|
||||
pub use video::FramediffArgs;
|
||||
pub use video::MeasureArgs;
|
||||
pub use video::MotionArgs;
|
||||
pub use video::SheetArgs;
|
||||
pub use viewer_command::GuiArgs;
|
||||
@@ -141,6 +142,8 @@ pub enum Command {
|
||||
Framediff(FramediffArgs),
|
||||
/// When a region was blank (one colour, such as white) or frozen
|
||||
Blank(BlankArgs),
|
||||
/// A statistic of a region (mean or peak brightness, drawn width) on a fixed-rate timeline
|
||||
Measure(MeasureArgs),
|
||||
/// Two recordings side by side: frames, motion, findings, annotations
|
||||
Compare(CompareArgs),
|
||||
/// A contact sheet image of frames, with the times, events and bug region marked
|
||||
@@ -231,6 +234,7 @@ impl Command {
|
||||
Self::Motion(args) => args.json,
|
||||
Self::Framediff(args) => args.json,
|
||||
Self::Blank(args) => args.json,
|
||||
Self::Measure(args) => args.json,
|
||||
Self::Compare(args) => args.json,
|
||||
Self::Annotate(args) => args.json(),
|
||||
Self::Annotations(args) => args.json,
|
||||
@@ -314,6 +318,7 @@ pub fn run(command: Command) -> eyre::Result<()> {
|
||||
Command::Motion(args) => video::motion(&args),
|
||||
Command::Framediff(args) => video::framediff(&args),
|
||||
Command::Blank(args) => video::blank(&args),
|
||||
Command::Measure(args) => video::measure(&args),
|
||||
Command::Compare(args) => video::compare(&args),
|
||||
Command::Findings(args) => findings::findings(&args),
|
||||
Command::Annotate(args) => annotate::annotate(&args),
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//! | `motion` | [`Analysis::motion`] | `motion/1` |
|
||||
//! | `framediff` | [`framediff`](crate::analysis::framediff::framediff) | `framediff/1` |
|
||||
//! | `blank` | [`Analysis::blank`] | `blank/1` |
|
||||
//! | `measure` | [`Analysis::measure`] | `measure/1` |
|
||||
//! | `compare` | [`Analysis::compare`] | `compare/1` |
|
||||
//!
|
||||
//! Both work on a range of video time, given as `--from` and `--to` (any time `state --at` takes;
|
||||
@@ -33,6 +34,10 @@ use crate::analysis::framediff::DEFAULT_WIDTH;
|
||||
use crate::analysis::framediff::FrameAt;
|
||||
use crate::analysis::framediff::FrameDiffOptions;
|
||||
use crate::analysis::framediff::SCHEMA_FRAMEDIFF;
|
||||
use crate::analysis::measure::DEFAULT_HZ;
|
||||
use crate::analysis::measure::MeasureOptions;
|
||||
use crate::analysis::measure::SCHEMA_MEASURE;
|
||||
use crate::analysis::measure::Statistic;
|
||||
use crate::analysis::motion::SCHEMA_MOTION;
|
||||
use crate::analysis::motion::ScanOptions;
|
||||
use crate::analysis::pixels::Crop;
|
||||
@@ -199,6 +204,38 @@ pub struct BlankArgs {
|
||||
pub json: bool,
|
||||
}
|
||||
|
||||
/// The arguments of `measure`.
|
||||
#[derive(Args, Debug)]
|
||||
pub struct MeasureArgs {
|
||||
/// Session directory
|
||||
pub session: PathBuf,
|
||||
/// The region to measure, in display points: x,y,w,h [default: the whole display]
|
||||
#[arg(long, value_name = "X,Y,W,H")]
|
||||
pub region: Option<String>,
|
||||
/// What to measure, repeatable: mean (brightness), peak (brightness), width (drawn width, in
|
||||
/// points) [default: all three]
|
||||
#[arg(long = "stat", value_name = "STAT")]
|
||||
pub stats: Vec<Statistic>,
|
||||
/// Samples per second of the fixed-rate timeline
|
||||
#[arg(long, default_value_t = DEFAULT_HZ)]
|
||||
pub hz: f64,
|
||||
/// The brightness (0 to 255) that is background for `width` [default: the most common one in the region]
|
||||
#[arg(long, value_name = "0-255")]
|
||||
pub background: Option<u8>,
|
||||
/// Only this display (repeatable) [default: every display with video]
|
||||
#[arg(long = "display", value_name = "ID")]
|
||||
pub displays: Vec<u32>,
|
||||
/// From this moment [default: the start of the video]
|
||||
#[arg(long, value_name = "TIME")]
|
||||
pub from: Option<String>,
|
||||
/// To this moment [default: the end of the video]
|
||||
#[arg(long, value_name = "TIME")]
|
||||
pub to: Option<String>,
|
||||
/// Machine-readable JSON output
|
||||
#[arg(long)]
|
||||
pub json: bool,
|
||||
}
|
||||
|
||||
/// The arguments of `compare`.
|
||||
#[derive(Args, Debug)]
|
||||
pub struct CompareArgs {
|
||||
@@ -489,6 +526,41 @@ pub(super) fn blank(args: &BlankArgs) -> eyre::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn measure(args: &MeasureArgs) -> eyre::Result<()> {
|
||||
let analysis = Analysis::open(&args.session)?;
|
||||
let video = SessionVideo::new(&analysis.manifest, analysis.guard());
|
||||
let (from, to) = range(&analysis, args.from.as_deref(), args.to.as_deref(), None)?;
|
||||
let shown = displays(&video, &args.displays)?;
|
||||
let mut statistics = if args.stats.is_empty() {
|
||||
Statistic::ALL.to_vec()
|
||||
} else {
|
||||
args.stats.clone()
|
||||
};
|
||||
statistics.dedup();
|
||||
|
||||
let data = analysis.measure(
|
||||
&video,
|
||||
&MeasureOptions {
|
||||
scan: ScanOptions {
|
||||
displays: &shown,
|
||||
from_s: from,
|
||||
to_s: to,
|
||||
crop: region(args.region.as_deref())?,
|
||||
cancel: None,
|
||||
},
|
||||
statistics: &statistics,
|
||||
hz: args.hz,
|
||||
background: args.background,
|
||||
},
|
||||
)?;
|
||||
if args.json {
|
||||
return print_json(&Envelope::ok(SCHEMA_MEASURE, data).warnings(analysis.warnings()));
|
||||
}
|
||||
|
||||
print!("{}", data.to_text());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn compare(args: &CompareArgs) -> eyre::Result<()> {
|
||||
let a = Analysis::open(&args.session_a)?;
|
||||
let b = Analysis::open(&args.session_b)?;
|
||||
|
||||
@@ -555,3 +555,62 @@ fn a_sheet_draws_the_windows_of_the_moment_and_says_so_when_there_is_no_track()
|
||||
assert!(warnings.contains("no window track"), "{warnings}");
|
||||
assert!(answer["data"]["frames"][0].get("windows").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn measure_puts_a_region_on_a_fixed_rate_timeline() {
|
||||
let Some(dir) = session("video-measure") else {
|
||||
return;
|
||||
};
|
||||
|
||||
let measured = json(&[
|
||||
"measure",
|
||||
&dir,
|
||||
"--display",
|
||||
"1",
|
||||
"--from",
|
||||
"0",
|
||||
"--to",
|
||||
"1",
|
||||
"--hz",
|
||||
"10",
|
||||
"--json",
|
||||
]);
|
||||
assert_eq!(measured["schema"], "measure/1");
|
||||
let data = &measured["data"];
|
||||
assert_eq!(data["statistics"], json!(["mean", "peak", "width"]));
|
||||
let samples = data["series"][0]["samples"].as_array().expect("samples");
|
||||
assert_eq!(samples.len(), 11);
|
||||
for (index, sample) in samples.iter().enumerate() {
|
||||
assert!((sample["video_s"].as_f64().expect("time") - index as f64 / 10.0).abs() < 1e-9);
|
||||
let shown = sample["shown_s"].as_f64().expect("a frame is on screen");
|
||||
assert!(shown <= sample["video_s"].as_f64().expect("time") + 1e-9);
|
||||
}
|
||||
|
||||
// display 2 has no video before 1 s
|
||||
let late = json(&[
|
||||
"measure",
|
||||
&dir,
|
||||
"--display",
|
||||
"2",
|
||||
"--from",
|
||||
"0",
|
||||
"--to",
|
||||
"1.5",
|
||||
"--hz",
|
||||
"2",
|
||||
"--stat",
|
||||
"peak",
|
||||
"--json",
|
||||
]);
|
||||
let samples = late["data"]["series"][0]["samples"]
|
||||
.as_array()
|
||||
.expect("samples");
|
||||
assert!(samples[0]["values"][0].is_null());
|
||||
assert!(!samples[2]["values"][0].is_null());
|
||||
|
||||
// a rate that is not a rate
|
||||
assert_eq!(
|
||||
recorder(&["measure", &dir, "--hz", "0"]).status.code(),
|
||||
Some(2)
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user