app: cut miniatures for the clips grid
Each card's stage shows a frame of the clip now, cut once with ffmpeg into a thumbs folder beside the clips and reused from there. The pass runs one clip at a time on a thread, skips what is already on disk and as new as its clip, and poll drops each finished picture into its card as it lands. Deleting a clip takes its miniature with it. The frame is the clip's first: an export starts on the moment the clip was cut for, so the picture shows the action without a seek. A clip re-exported over the same name keeps its old picture until restart, because the image cache keys a file by its path alone.
This commit is contained in:
1 parent
3f82f87a81
commit
83ca4071d4
5 files changed
+196
-25
No files matched your search
@@ -142,6 +142,10 @@ pub struct App {
|
||||
/// Every clip the user exported, newest first. Read when the screen opens.
|
||||
pub clips: Vec<Clip>,
|
||||
pub clips_loaded: bool,
|
||||
/// The clips' miniatures, decoded off the render path and cached by file.
|
||||
pub thumbs: Option<rune::ImageCache>,
|
||||
/// A miniature on its way: the clip's name and the file that holds it.
|
||||
pub thumbs_rx: Option<Receiver<(String, PathBuf)>>,
|
||||
/// The clip card whose actions menu is open, if any: its position, like the history's.
|
||||
pub clips_menu_open: Option<usize>,
|
||||
/// The clip the delete dialog is about, by its `id@start` key.
|
||||
@@ -201,6 +205,8 @@ impl App {
|
||||
menu_open: None,
|
||||
clips: Vec::new(),
|
||||
clips_loaded: false,
|
||||
thumbs: None,
|
||||
thumbs_rx: None,
|
||||
clips_menu_open: None,
|
||||
confirm_clip_delete: None,
|
||||
review: screens::review::Review::default(),
|
||||
@@ -250,6 +256,7 @@ impl App {
|
||||
Clip {
|
||||
name,
|
||||
path: PathBuf::new(),
|
||||
thumb: None,
|
||||
exported: Some(
|
||||
std::time::SystemTime::now()
|
||||
- chrono::Duration::hours(hours_ago)
|
||||
@@ -475,9 +482,38 @@ impl App {
|
||||
}
|
||||
|
||||
/// Read the clips folder into the grid. A directory read, quick enough for the UI thread.
|
||||
/// The miniatures are ffmpeg work, so their pass runs on a thread of its own and `poll`
|
||||
/// picks each one up as it lands.
|
||||
pub fn refresh_clips(&mut self) {
|
||||
self.clips = export::list_clips();
|
||||
self.clips_loaded = true;
|
||||
self.spawn_thumbs();
|
||||
}
|
||||
|
||||
/// Cut every missing miniature, one clip at a time, on a thread of its own; `poll` picks
|
||||
/// each one up as it lands. One pass at a time: the next refresh starts another.
|
||||
pub fn spawn_thumbs(&mut self) {
|
||||
if self.thumbs_rx.is_some() {
|
||||
return;
|
||||
}
|
||||
let clips = self.clips.clone();
|
||||
let (tx, rx) = channel();
|
||||
std::thread::spawn(move || {
|
||||
for clip in &clips {
|
||||
if export::thumb_of(clip).is_some() {
|
||||
continue;
|
||||
}
|
||||
let Some(source) = export::source_of(clip) else {
|
||||
continue;
|
||||
};
|
||||
let thumb = export::thumb_path(clip);
|
||||
let cut = export::make_thumb(&source, &thumb);
|
||||
if cut && tx.send((clip.name.clone(), thumb)).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
self.thumbs_rx = Some(rx);
|
||||
}
|
||||
|
||||
/// Read the next page of rows, if the list has one and none is already on its way.
|
||||
@@ -568,6 +604,7 @@ pub fn setup(app: &mut App, waker: rune::Waker) {
|
||||
app.waker = Some(waker.clone());
|
||||
app.portraits = Some(portraits::Portraits::new(waker.clone()));
|
||||
app.icons = Some(rune::ImageCache::new(waker.clone()));
|
||||
app.thumbs = Some(rune::ImageCache::new(waker.clone()));
|
||||
app.daemon.set_waker(waker.clone());
|
||||
app.refresh_settings();
|
||||
app.refresh_games();
|
||||
@@ -754,6 +791,26 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(rx) = &self.thumbs_rx {
|
||||
let mut landed = false;
|
||||
loop {
|
||||
match rx.try_recv() {
|
||||
Ok((name, thumb)) => {
|
||||
if let Some(clip) = self.clips.iter_mut().find(|clip| clip.name == name) {
|
||||
clip.thumb = Some(thumb);
|
||||
landed = true;
|
||||
}
|
||||
}
|
||||
Err(TryRecvError::Empty) => break,
|
||||
Err(TryRecvError::Disconnected) => {
|
||||
self.thumbs_rx = None;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
changed |= landed;
|
||||
}
|
||||
|
||||
// The clips grid reads the clips folder, so it loads once it is on screen, not at launch.
|
||||
if self.screen == Screen::Clips && !self.clips_loaded {
|
||||
self.refresh_clips();
|
||||
|
||||
Reference in new issue
Block a user