Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

export: show the estimated time left of a render next to its percentage

Dario Carnelutti283ea80a62e3
diff --git a/crates/engine/src/export_tests.rs b/crates/engine/src/export_tests.rs
index 62f220930..e69884ab9 100644
--- a/crates/engine/src/export_tests.rs
+++ b/crates/engine/src/export_tests.rs
@@ -363,6 +363,47 @@ fn queue_cancels_a_running_export_and_retries_a_failed_one() {
assert!(queue(&mut s).iter().all(|i| i["id"] != bad));
}
+#[test]
+fn jobs_and_queue_items_report_the_time_they_have_left() {
+ use std::sync::atomic::Ordering;
+ use std::time::Duration;
+
+ use crate::export_tools::QueueStatus;
+ let mut s = demo();
+ let dir = Scratch::new("eta");
+ let job = crate::Job { id: 77, label: "Exporting".into(), progress: Default::default(), result: Default::default() };
+ job.progress.total.store(1000, Ordering::Relaxed);
+ assert!(job.to_json()["etaSeconds"].is_null(), "no speed measured yet");
+ // 50 units a second for 5 s, read from the near future (the JSON reads the real clock, which is then behind them)
+ let t0 = web_time::Instant::now() + Duration::from_secs(60);
+ for i in 0..=50u64 {
+ job.progress.done.store(i * 5, Ordering::Relaxed);
+ job.progress.eta_at(t0 + Duration::from_millis(i * 100));
+ }
+ let eta = job.to_json()["etaSeconds"].as_f64().expect("a number once the job has a speed");
+ assert!((eta - 15.0).abs() < 0.5, "750 units left at 50 a second: {eta}");
+ s.jobs.push(job);
+
+ // a queue item encoding that job shows it; one that waits shows nothing
+ for name in ["a.wav", "b.wav"] {
+ s.execute(
+ "export.queue.add",
+ json!({"preset": "Waveform Audio 48 kHz 16-bit", "path": dir.path(name), "range": "custom", "startSeconds": 0, "endSeconds": 0.25}),
+ )
+ .unwrap();
+ }
+ s.export_queue.items[0].status = QueueStatus::Encoding;
+ s.export_queue.items[0].job = Some(77);
+ let items = queue(&mut s);
+ assert!((items[0]["etaSeconds"].as_f64().expect("encoding") - 15.0).abs() < 0.5, "{}", items[0]);
+ assert_eq!(items[0]["status"], "encoding");
+ assert!(items[1]["etaSeconds"].is_null(), "{}", items[1]);
+ // and `jobs.list` carries it too
+ let jobs = s.execute("jobs.list", json!({})).unwrap();
+ let listed = jobs["jobs"].as_array().or(jobs.as_array()).expect("a list of jobs").iter().find(|j| j["id"] == 77).cloned().expect("the job is listed");
+ assert!(listed["etaSeconds"].as_f64().is_some(), "{listed}");
+}
+
#[test]
fn queue_exports_several_sequences_and_ranges() {
let mut s = demo();
diff --git a/crates/engine/src/export_tools.rs b/crates/engine/src/export_tools.rs
index a6cee1284..6e19fd9aa 100644
--- a/crates/engine/src/export_tools.rs
+++ b/crates/engine/src/export_tools.rs
@@ -516,6 +516,7 @@ fn item_json(s: &Session, it: &QueueItem) -> Value {
"range": it.settings.range,
"status": it.status,
"progress": progress,
+ "etaSeconds": job.filter(|_| it.status == QueueStatus::Encoding).and_then(|j| j.progress.eta()).map(|d| d.as_secs_f64()),
"statusText": status_text,
"job": it.job,
"error": it.error,
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 10bef2c19..b0780319a 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -404,6 +404,8 @@ impl Job {
"id": self.id,
"label": self.label,
"progress": self.progress.fraction(),
+ // seconds left at the job's recent speed; null until it can tell
+ "etaSeconds": self.progress.eta().map(|d| d.as_secs_f64()),
"done": self.progress.done.load(Ordering::Relaxed),
"total": self.progress.total.load(Ordering::Relaxed),
"status": self.progress.status.lock().unwrap_or_else(|e| e.into_inner()).clone(),
diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs
index d50e1f30c..2be1cce7c 100644
--- a/crates/export/src/lib.rs
+++ b/crates/export/src/lib.rs
@@ -18,6 +18,7 @@ use std::io::Write;
mod audio_out;
mod job;
mod mxf_out;
+mod pace;
mod pcm;
mod pipeline;
pub mod presets;
@@ -470,6 +471,8 @@ pub struct Progress {
pub error: Mutex<Option<String>>,
/// What loudness normalization measured (when it ran).
pub loudness: Mutex<Option<LoudnessReport>>,
+ /// Readings of `done` over time, for [`Progress::eta`].
+ pace: Mutex<pace::Pace>,
}
impl Progress {
@@ -477,6 +480,24 @@ impl Progress {
let t = self.total.load(Ordering::Relaxed).max(1);
self.done.load(Ordering::Relaxed) as f32 / t as f32
}
+
+ /// The estimated time left, from the job's speed over the last 15 seconds. Each call is also a
+ /// reading of that speed, so ask regularly (the UI does on every frame it draws the job).
+ /// `None` until a second of readings shows progress, and once the job is done or finished.
+ pub fn eta(&self) -> Option<std::time::Duration> {
+ self.eta_at(web_time::Instant::now())
+ }
+
+ /// [`Progress::eta`] at a given time (tests, and hosts with a clock of their own).
+ pub fn eta_at(&self, now: web_time::Instant) -> Option<std::time::Duration> {
+ let (done, total) = (self.done.load(Ordering::Relaxed), self.total.load(Ordering::Relaxed));
+ let mut pace = self.pace.lock().unwrap_or_else(|e| e.into_inner());
+ pace.observe(now, done);
+ if self.finished.load(Ordering::Relaxed) || done >= total {
+ return None;
+ }
+ pace.eta(total - done)
+ }
fn set_status(&self, s: impl Into<String>) {
*self.status.lock().unwrap_or_else(|e| e.into_inner()) = s.into();
}
diff --git a/crates/export/src/pace.rs b/crates/export/src/pace.rs
new file mode 100644
index 000000000..77e75516a
--- /dev/null
+++ b/crates/export/src/pace.rs
@@ -0,0 +1,225 @@
+//! Estimated time left of a job, from how fast it advanced over the last seconds.
+//!
+//! A job's `done` counter goes up in batches, and the speed of an export changes with what is on the
+//! timeline (an intro, a banner, plain camera footage), so the estimate uses the speed of a trailing
+//! window, not the average since the start, and it stays quiet until a second of readings shows
+//! progress. A stall shows as a falling speed, so the estimate grows instead of freezing.
+
+use std::collections::VecDeque;
+use std::time::Duration;
+
+use web_time::Instant;
+
+/// How far back the speed is measured.
+const WINDOW: Duration = Duration::from_secs(15);
+/// Readings closer together than this are one reading (the UI asks on every frame it draws).
+const MIN_GAP: Duration = Duration::from_millis(100);
+/// The estimate needs at least this much time between its first and last reading.
+const MIN_SPAN: Duration = Duration::from_secs(1);
+/// The longest estimate given: a job that all but stopped would otherwise promise millennia.
+const MAX_ETA: Duration = Duration::from_secs(100 * 3600);
+
+/// Readings of a job's `done` counter over time.
+#[derive(Default)]
+pub(crate) struct Pace {
+ /// (when, `done` then), oldest first.
+ readings: VecDeque<(Instant, u64)>,
+}
+
+impl Pace {
+ /// Note that the job had done `done` units at `now`.
+ pub(crate) fn observe(&mut self, now: Instant, done: u64) {
+ // a count that went back (a job that started over) starts the history again
+ if self.readings.back().is_some_and(|(_, d)| done < *d) {
+ self.readings.clear();
+ }
+ if self.readings.back().is_none_or(|(t, _)| now.saturating_duration_since(*t) >= MIN_GAP) {
+ self.readings.push_back((now, done));
+ }
+ // keep the newest reading that is a whole window old as the baseline, and nothing before it
+ while self.readings.len() > 2 && self.readings.get(1).is_some_and(|(t, _)| now.saturating_duration_since(*t) >= WINDOW) {
+ self.readings.pop_front();
+ }
+ // an idle start (a loudness pass, a slow seek) is not the job's speed: measure from the last
+ // reading before it moved, not from a baseline that makes the job look slow for a whole window
+ if let Some(first) = self.readings.front().map(|r| r.1)
+ && let Some(moved) = self.readings.iter().position(|(_, d)| *d != first)
+ && moved >= 2
+ && self.readings.get(moved - 1).is_some_and(|(t, _)| t.saturating_duration_since(self.readings[0].0) >= MIN_SPAN)
+ {
+ self.readings.drain(..moved - 1);
+ }
+ }
+
+ /// The time `remaining` more units take at the pace of the readings, when they show one.
+ pub(crate) fn eta(&self, remaining: u64) -> Option<Duration> {
+ let (t0, d0) = *self.readings.front()?;
+ let (t1, d1) = *self.readings.back()?;
+ let span = t1.saturating_duration_since(t0);
+ if span < MIN_SPAN || d1 <= d0 {
+ return None;
+ }
+ let per_second = (d1 - d0) as f64 / span.as_secs_f64();
+ let left = remaining as f64 / per_second;
+ // `try_from_secs_f64` refuses what a `Duration` cannot hold; that is "more than the cap" here
+ (left >= 0.0).then(|| Duration::try_from_secs_f64(left).map_or(MAX_ETA, |d| d.min(MAX_ETA)))
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn at(t0: Instant, secs: f64) -> Instant {
+ t0 + Duration::from_secs_f64(secs)
+ }
+
+ /// Feed `readings` (seconds, done) and ask for the time left of `total`.
+ fn eta(readings: &[(f64, u64)], total: u64) -> Option<f64> {
+ let t0 = Instant::now();
+ let mut p = Pace::default();
+ for (s, d) in readings {
+ p.observe(at(t0, *s), *d);
+ }
+ let done = readings.last().map_or(0, |r| r.1);
+ p.eta(total.saturating_sub(done)).map(|d| d.as_secs_f64())
+ }
+
+ /// A job at `fps` units per second, read every `step` seconds for `secs`.
+ fn steady(fps: f64, step: f64, secs: f64) -> Vec<(f64, u64)> {
+ (0..=(secs / step) as u64).map(|i| (i as f64 * step, (i as f64 * step * fps) as u64)).collect()
+ }
+
+ #[test]
+ fn a_steady_job_gives_the_time_it_has_left() {
+ // 50 units a second, 4 s in, of 1000: 800 units left = 16 s
+ let e = eta(&steady(50.0, 0.15, 4.0), 1000).unwrap();
+ assert!((e - 16.0).abs() < 0.5, "{e}");
+ // and the estimate falls as the job goes on: 10 s in, 500 left
+ let e = eta(&steady(50.0, 0.15, 10.0), 1000).unwrap();
+ assert!((e - 10.0).abs() < 0.5, "{e}");
+ }
+
+ #[test]
+ fn nothing_is_promised_before_there_is_progress_to_measure() {
+ assert_eq!(eta(&[], 100), None);
+ assert_eq!(eta(&[(0.0, 0)], 100), None, "one reading");
+ assert_eq!(eta(&[(0.0, 0), (0.5, 20)], 100), None, "less than a second of readings");
+ assert_eq!(eta(&[(0.0, 5), (2.0, 5)], 100), None, "nothing done in two seconds (a loudness pass, a seek)");
+ // then, once frames flow
+ assert!(eta(&[(0.0, 0), (2.0, 0), (3.0, 30)], 100).is_some());
+ }
+
+ #[test]
+ fn the_estimate_follows_a_change_of_speed_within_the_window() {
+ // 100 units a second for 20 s, then 20 a second for 20 s (a banner comes in): the last
+ // 15 s dominate, so with 10 000 units to do the estimate is near the slow speed's
+ let mut r = steady(100.0, 0.15, 20.0);
+ let (t, d) = *r.last().unwrap();
+ r.extend((1..=133).map(|i| (t + i as f64 * 0.15, d + (i as f64 * 0.15 * 20.0) as u64)));
+ let done = r.last().unwrap().1;
+ let e = eta(&r, 10_000).unwrap();
+ let slow = (10_000 - done) as f64 / 20.0;
+ let fast = (10_000 - done) as f64 / 100.0;
+ assert!((e - slow).abs() < (e - fast).abs(), "estimate {e}, slow {slow}, fast {fast}");
+ }
+
+ #[test]
+ fn an_idle_start_does_not_hold_the_estimate_back() {
+ // 20 s with nothing done (a loudness pass), then 50 units a second for 3 s: the pace is 50 a
+ // second, not what a 15 s window that is mostly idle would say
+ let mut r: Vec<(f64, u64)> = (0..=133).map(|i| (i as f64 * 0.15, 0)).collect();
+ let t = r.last().unwrap().0;
+ r.extend((1..=20).map(|i| (t + i as f64 * 0.15, (i as f64 * 0.15 * 50.0) as u64)));
+ let e = eta(&r, 1000).unwrap();
+ let done = r.last().unwrap().1;
+ assert!((e - (1000 - done) as f64 / 50.0).abs() < 1.0, "{e}");
+ // the short flat spells between batches of a running job are not an idle start
+ let batches: Vec<(f64, u64)> = (0..=40).map(|i| (i as f64 * 0.15, (i / 2) as u64 * 8)).collect();
+ assert!(eta(&batches, 1000).is_some());
+ }
+
+ #[test]
+ fn a_stall_makes_the_estimate_grow() {
+ let mut r = steady(50.0, 0.15, 4.0);
+ let before = eta(&r, 1000).unwrap();
+ let (t, d) = *r.last().unwrap();
+ r.extend((1..=40).map(|i| (t + i as f64 * 0.15, d)));
+ let after = eta(&r, 1000).unwrap();
+ assert!(after > before * 1.5, "{before} -> {after}");
+ }
+
+ #[test]
+ fn a_count_that_goes_back_starts_over() {
+ // a second pass, or a job reusing its counters: the old history must not count
+ let mut r = steady(50.0, 0.15, 4.0);
+ let (t, _) = *r.last().unwrap();
+ r.extend((1..=20).map(|i| (t + i as f64 * 0.15, (i as f64 * 0.15 * 10.0) as u64)));
+ let e = eta(&r, 100).unwrap();
+ let done = r.last().unwrap().1;
+ assert!((e - (100 - done) as f64 / 10.0).abs() < 1.0, "{e}");
+ }
+
+ #[test]
+ fn readings_that_arrive_together_count_once_and_the_history_stays_small() {
+ let t0 = Instant::now();
+ let mut p = Pace::default();
+ for _ in 0..1000 {
+ p.observe(t0, 1);
+ }
+ assert_eq!(p.readings.len(), 1);
+ // an hour of 150 ms readings keeps about a window of them
+ for i in 0..24_000u64 {
+ p.observe(at(t0, 1.0 + i as f64 * 0.15), 1 + i);
+ }
+ assert!(p.readings.len() <= (WINDOW.as_millis() / MIN_GAP.as_millis()) as usize + 3, "{}", p.readings.len());
+ }
+
+ #[test]
+ fn a_job_reports_its_time_left_until_it_is_done() {
+ use std::sync::atomic::Ordering;
+ let t0 = Instant::now();
+ let progress = crate::Progress::default();
+ // no total yet, nothing to estimate
+ assert_eq!(progress.eta_at(t0), None);
+ progress.total.store(1000, Ordering::Relaxed);
+ let mut last = None;
+ for i in 0..=60u64 {
+ progress.done.store(i * 5, Ordering::Relaxed); // 50 units a second, read every 0.1 s
+ last = progress.eta_at(at(t0, i as f64 * 0.1));
+ }
+ // 6 s in, 300 done, 700 left at 50 a second
+ let left = last.expect("a second of readings shows progress").as_secs_f64();
+ assert!((left - 14.0).abs() < 0.5, "{left}");
+ // done: nothing left to wait for
+ progress.done.store(1000, Ordering::Relaxed);
+ assert_eq!(progress.eta_at(at(t0, 7.0)), None);
+ // a finished job (cancelled, failed) has none either, whatever it had left
+ let other = crate::Progress::default();
+ other.total.store(1000, Ordering::Relaxed);
+ for i in 0..=30u64 {
+ other.done.store(i * 5, Ordering::Relaxed);
+ other.eta_at(at(t0, i as f64 * 0.1));
+ }
+ assert!(other.eta_at(at(t0, 3.1)).is_some());
+ other.finished.store(true, Ordering::Relaxed);
+ assert_eq!(other.eta_at(at(t0, 3.2)), None);
+ }
+
+ #[test]
+ fn extreme_numbers_give_a_capped_estimate_or_none_and_never_panic() {
+ // almost no progress against a huge total: capped
+ let e = eta(&[(0.0, 0), (10.0, 1)], u64::MAX).unwrap();
+ assert!((e - MAX_ETA.as_secs_f64()).abs() < 1.0, "{e}");
+ // huge counters
+ assert!(eta(&[(0.0, u64::MAX - 100), (2.0, u64::MAX - 50)], u64::MAX).is_some());
+ // a clock that does not move forward: no estimate, no division by zero
+ assert_eq!(eta(&[(1.0, 0), (1.0, 50), (1.0, 100)], 1000), None);
+ // nothing left
+ let t0 = Instant::now();
+ let mut p = Pace::default();
+ p.observe(t0, 0);
+ p.observe(at(t0, 2.0), 100);
+ assert_eq!(p.eta(0), Some(Duration::ZERO));
+ }
+}
diff --git a/crates/export/src/settings.rs b/crates/export/src/settings.rs
index 76a4443e7..69c4dc00e 100644
--- a/crates/export/src/settings.rs
+++ b/crates/export/src/settings.rs
@@ -537,6 +537,16 @@ impl ExportSettings {
}
}
+/// A time left, rounded up to the second: `45 s`, `2:05`, `1:02:05`.
+pub fn format_eta(d: std::time::Duration) -> String {
+ let s = d.as_secs().saturating_add(u64::from(d.subsec_nanos() > 0));
+ match s {
+ 0..=59 => format!("{s} s"),
+ 60..=3599 => format!("{}:{:02}", s / 60, s % 60),
+ _ => format!("{}:{:02}:{:02}", s / 3600, s % 3600 / 60, s % 60),
+ }
+}
+
/// `1.2 GB`, `350 MB`, `12 KB`.
pub fn format_bytes(b: u64) -> String {
let b = b as f64;
diff --git a/crates/export/src/settings_tests.rs b/crates/export/src/settings_tests.rs
index 4a7562fee..78dd22be3 100644
--- a/crates/export/src/settings_tests.rs
+++ b/crates/export/src/settings_tests.rs
@@ -410,3 +410,20 @@ fn aac_bitrate_is_capped_for_low_sample_rates() {
assert!(enc.is_ok(), "{rate} Hz × {ch}: {:?}", enc.err());
}
}
+
+#[test]
+fn a_time_left_reads_like_a_clock() {
+ use std::time::Duration;
+ let f = |ms: u64| format_eta(Duration::from_millis(ms));
+ assert_eq!(f(0), "0 s");
+ assert_eq!(f(1), "1 s", "rounded up: never say 0 s while there is time left");
+ assert_eq!(f(45_000), "45 s");
+ assert_eq!(f(59_001), "1:00");
+ assert_eq!(f(60_000), "1:00");
+ assert_eq!(f(125_000), "2:05");
+ assert_eq!(f(3_599_000), "59:59");
+ assert_eq!(f(3_600_000), "1:00:00");
+ assert_eq!(f(3_725_000), "1:02:05");
+ assert_eq!(f(100 * 3600 * 1000), "100:00:00");
+ assert!(!format_eta(Duration::MAX).is_empty(), "the largest duration cannot overflow");
+}
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index e7779a907..1062b452e 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -1229,20 +1229,27 @@ impl FilmcraftApp {
}
ui.ctx().request_repaint_after(std::time::Duration::from_millis(150));
let f = job.progress.fraction().clamp(0.0, 1.0);
+ let left = job.progress.eta().map(panels::left_text).unwrap_or_default();
let cancel = egui::Rect::from_center_size(egui::pos2(sb.max.x - 14.0, sb.center().y), egui::vec2(14.0, 14.0));
let bar = egui::Rect::from_min_size(egui::pos2(cancel.min.x - 128.0, sb.center().y - 3.0), egui::vec2(120.0, 6.0));
let p = ui.painter();
p.rect_filled(bar, 3.0, t.separator);
p.rect_filled(egui::Rect::from_min_size(bar.min, egui::vec2(bar.width() * f, bar.height())), 3.0, t.accent);
let verb = if job.label.starts_with("Rendering") { job.label.clone() } else { "Exporting".to_string() };
- p.text(egui::pos2(bar.min.x - 8.0, sb.center().y), egui::Align2::RIGHT_CENTER, format!("{verb}… {:.0}%", f * 100.0), Tokens::ui(11.0), t.text_dim);
+ p.text(
+ egui::pos2(bar.min.x - 8.0, sb.center().y),
+ egui::Align2::RIGHT_CENTER,
+ format!("{verb}… {:.0}%{left}", f * 100.0),
+ Tokens::ui(11.0),
+ t.text_dim,
+ );
let resp = ui.interact(cancel, egui::Id::new(("job-cancel", job.id)), egui::Sense::click());
let c = if resp.hovered() { t.hot_text } else { t.text_dim };
let k = 3.5;
p.line_segment([cancel.center() - egui::vec2(k, k), cancel.center() + egui::vec2(k, k)], egui::Stroke::new(1.4, c));
p.line_segment([cancel.center() + egui::vec2(-k, k), cancel.center() + egui::vec2(k, -k)], egui::Stroke::new(1.4, c));
self.auto.add("status.job.cancel", cancel, &format!("Cancel {}", job.label));
- self.auto.add("status.job.progress", bar, &format!("{:.0}%", f * 100.0));
+ self.auto.add("status.job.progress", bar, &format!("{:.0}%{left}", f * 100.0));
if resp.on_hover_text("Cancel").clicked() {
job.progress.cancel.store(true, Ordering::Relaxed);
self.watched_render = None;
diff --git a/crates/ui-egui/src/panels/events.rs b/crates/ui-egui/src/panels/events.rs
index 50df75ebb..d9649a0a4 100644
--- a/crates/ui-egui/src/panels/events.rs
+++ b/crates/ui-egui/src/panels/events.rs
@@ -179,7 +179,8 @@ pub fn progress(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
(false, _) => {
let s = j["status"].as_str().unwrap_or("");
let n = format!("{} / {}", j["done"].as_u64().unwrap_or(0), j["total"].as_u64().unwrap_or(0));
- if s.is_empty() { format!("{:.0} % ({n})", frac * 100.0) } else { format!("{:.0} % {s}", frac * 100.0) }
+ let left = super::eta_suffix(j);
+ if s.is_empty() { format!("{:.0} % ({n}){left}", frac * 100.0) } else { format!("{:.0} % {s}{left}", frac * 100.0) }
}
};
let bar = Rect::from_min_max(pos2(r.min.x + 8.0, r.min.y + 24.0), pos2(r.max.x - 36.0, r.min.y + 30.0));
diff --git a/crates/ui-egui/src/panels/export_mode.rs b/crates/ui-egui/src/panels/export_mode.rs
index c9446a7fe..cf55ba959 100644
--- a/crates/ui-egui/src/panels/export_mode.rs
+++ b/crates/ui-egui/src/panels/export_mode.rs
@@ -223,12 +223,18 @@ fn queue_column(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
let preset = it["preset"].as_str().filter(|s| !s.is_empty()).unwrap_or(CUSTOM);
let (label, col) = match status {
"ready" => ("Ready".to_string(), t.text_dim),
- "encoding" => (format!("Encoding {:.0}%", it["progress"].as_f64().unwrap_or(0.0) * 100.0), t.accent),
+ "encoding" => (format!("Encoding {:.0}%{}", it["progress"].as_f64().unwrap_or(0.0) * 100.0, super::eta_suffix(it)), t.accent),
"done" => ("Done".to_string(), t.render_green),
"failed" => (format!("Failed: {}", it["error"].as_str().unwrap_or("")), t.danger),
_ => ("Cancelled".to_string(), t.text_faint),
};
- ui.label(egui::RichText::new(format!("{preset} · {label}")).size(11.0).color(col));
+ if status == "encoding" {
+ // the progress and the time left on a line of their own: the column is narrow, and a wrapped "· 15 s left" reads badly
+ ui.label(egui::RichText::new(preset).size(11.0).color(t.text_dim));
+ ui.label(egui::RichText::new(label).size(11.0).color(col));
+ } else {
+ ui.label(egui::RichText::new(format!("{preset} · {label}")).size(11.0).color(col));
+ }
if status == "encoding" {
ui.add(egui::ProgressBar::new(it["progress"].as_f64().unwrap_or(0.0) as f32).desired_height(6.0));
}
diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs
index 9099daf47..f5510dd40 100644
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@ -55,6 +55,16 @@ use crate::FilmcraftApp;
use crate::dock::PanelKind;
use crate::theme::Tokens;
+/// ` · 2:05 left`: the time a job has left, as it follows a percentage.
+pub fn left_text(d: std::time::Duration) -> String {
+ format!(" · {} left", filmcraft_engine::export::format_eta(d))
+}
+
+/// [`left_text`] for a job or queue item whose JSON has `etaSeconds`, nothing while it is null.
+pub fn eta_suffix(job: &serde_json::Value) -> String {
+ job["etaSeconds"].as_f64().and_then(|s| std::time::Duration::try_from_secs_f64(s).ok()).map(left_text).unwrap_or_default()
+}
+
pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, p: PanelKind, rect: Rect) {
match p {
PanelKind::Program if !app.session.state.edit_points.is_empty() => trim_monitor::show(app, ui, rect),
diff --git a/crates/ui-egui/tests/export_ui.rs b/crates/ui-egui/tests/export_ui.rs
index ae15af445..dd4a7704c 100644
--- a/crates/ui-egui/tests/export_ui.rs
+++ b/crates/ui-egui/tests/export_ui.rs
@@ -178,6 +178,46 @@ fn export_mode_settings_and_summary() {
d.snapshot("export-mode");
}
+#[test]
+fn the_status_bar_and_the_queue_show_the_time_left() {
+ use std::sync::atomic::Ordering;
+ use std::time::Duration;
+
+ use filmcraft_engine::Job;
+ use filmcraft_engine::export_tools::QueueStatus;
+ let mut d = Driver::new("eta");
+ d.ok("ui.set", json!({"mode": "export"}));
+ d.frames(3);
+ d.exec(
+ "export.queue.add",
+ json!({"preset": "Waveform Audio 48 kHz 16-bit", "path": d.path("eta.wav"), "range": "custom", "startSeconds": 0.0, "endSeconds": 0.25}),
+ );
+ // a job at 25 %, doing 50 units a second: 750 left, 15 s (readings from the near future, because
+ // the app reads the real clock, which is then behind them)
+ let job = Job { id: 900, label: "Exporting".into(), progress: Default::default(), result: Default::default() };
+ job.progress.total.store(1000, Ordering::Relaxed);
+ let t0 = web_time::Instant::now() + Duration::from_secs(60);
+ for i in 0..=50u64 {
+ job.progress.done.store(i * 5, Ordering::Relaxed);
+ job.progress.eta_at(t0 + Duration::from_millis(i * 100));
+ }
+ d.app().session.jobs.push(job);
+ {
+ let item = &mut d.app().session.export_queue.items[0];
+ item.status = QueueStatus::Encoding;
+ item.job = Some(900);
+ }
+ d.frames(4);
+ // the status bar says it next to the percentage, and agents read it from the same label
+ let label = d.ok("ui.elements", json!({"prefix": "status.job.progress"}))[0]["label"].as_str().unwrap().to_string();
+ assert_eq!(label, "25% · 15 s left");
+ // the queue item has it too
+ let item = d.queue().into_iter().next().unwrap();
+ assert!((item["etaSeconds"].as_f64().unwrap() - 15.0).abs() < 0.5, "{item}");
+ assert_eq!(item["status"], "encoding");
+ d.snapshot("export-eta");
+}
+
#[test]
fn preset_manager_search_favourite_save_apply() {
let mut d = Driver::new("manager");
diff --git a/docs/agents.md b/docs/agents.md
index bb0eb7534..2f02bc91f 100644
--- a/docs/agents.md
+++ b/docs/agents.md
@@ -89,6 +89,10 @@ progress and stop it:
- The export runs as the same background job `jobs.list` shows. The session is locked only for short
polls, so other requests (`ping`, `doc_inspect`, `jobs.list`, …) are answered while it encodes.
+- Every job in `jobs.list`, and every encoding item of `export.queue.list`, carries `etaSeconds`: the
+ time left at the job's speed over the last 15 seconds, `null` until a second of progress has been
+ measured (a loudness pass, a seek) and once it is done. The app shows it as `37% · 2:05 left` in the
+ status bar, the Export queue and the Progress panel.
- With `"_meta": {"progressToken": T}` on the `tools/call`, the server sends
`notifications/progress` `{progressToken: T, progress: <frames done>, total: <frames>, message:
<job status>}` at most every 100 ms while frames advance. Without a token it sends none.