- various fixes

This commit is contained in:
w.pomp
2026-08-07 15:14:16 +02:00
parent e4de76f26c
commit a0d2359e55
13 changed files with 191 additions and 97 deletions
+6 -19
View File
@@ -2,18 +2,16 @@ use crate::axes::Axis;
use crate::colors::Color;
use crate::error::Error;
use crate::readers::{PixelType, Reader};
use crate::utils::progress::get_bar;
use crate::view::View;
use console::Term;
use ffmpeg_sidecar::command::FfmpegCommand;
use ffmpeg_sidecar::download::auto_download;
use ffmpeg_sidecar::event::{FfmpegEvent, LogLevel};
use indicatif::{ProgressBar, ProgressDrawTarget, ProgressStyle};
use itertools::Itertools;
use ndarray::{Array2, Array3, Dimension, IxDyn, s, stack};
use ordered_float::OrderedFloat;
use std::io::Write;
use std::path::Path;
use std::time::Duration;
pub struct MovieOptions {
velocity: f64,
@@ -138,20 +136,6 @@ fn cframe(frame: Array2<f64>, color: &[u8], a: f64, b: f64) -> Array3<f64> {
stack(ndarray::Axis(2), &view).unwrap()
}
/// a progress bar with an ok style that when py::detach is used also works in jupyter
pub fn get_bar(count: Option<usize>) -> ProgressBar {
let style = ProgressStyle::with_template(
"{spinner:.green} {percent}% [{wide_bar:.green/lime}] {pos:>7}/{len:7} [{elapsed}/{eta}, {per_sec:<5}]",
).expect("template should be working").progress_chars("#>-");
let bar = ProgressBar::with_draw_target(
count.map(|i| i as u64),
ProgressDrawTarget::term_like_with_hz(Box::new(Term::buffered_stdout()), 20),
)
.with_style(style);
bar.enable_steady_tick(Duration::from_millis(100));
bar
}
impl<D, R> View<D, R>
where
D: Dimension,
@@ -252,7 +236,10 @@ where
};
let rt = tokio::runtime::Runtime::new()?;
let bar = get_bar(Some(size_t));
let bar = get_bar(
Some(size_t),
Some("autoscaling movie brightness".to_string()),
);
let rt_bar = bar.clone();
let write_task = rt.spawn(async move {
for t in 0..size_t {
@@ -275,7 +262,7 @@ where
});
bar.finish();
let bar = get_bar(Some(size_t));
let bar = get_bar(Some(size_t), Some("saving movie".to_string()));
let rt_bar = bar.clone();
let progress_task = rt.spawn(async move {
for event in movie.iter().map_err(|e| Error::Ffmpeg(e.to_string()))? {