feat(player): add chunk/scene markers on progress bar
This commit is contained in:
52
src/overlay/chunk.rs
Normal file
52
src/overlay/chunk.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use anyhow::Context;
|
||||
use log::info;
|
||||
use serde::Deserialize;
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CutData {
|
||||
pub frame_count: u64,
|
||||
pub fps: f64,
|
||||
pub scenes: Vec<Scene>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone)]
|
||||
pub struct Scene {
|
||||
pub scene_number: u32,
|
||||
pub start_frame: u64,
|
||||
pub end_frame: u64,
|
||||
pub start_time: f64,
|
||||
pub end_time: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ChunkLoader {
|
||||
pub data: CutData,
|
||||
}
|
||||
|
||||
impl ChunkLoader {
|
||||
pub fn load(path: &Path) -> anyhow::Result<Self> {
|
||||
let content = fs::read_to_string(path)
|
||||
.with_context(|| format!("Failed to read chunk file: {:?}", path))?;
|
||||
let data: CutData = serde_json::from_str(&content)
|
||||
.with_context(|| format!("Failed to parse chunk JSON: {:?}", path))?;
|
||||
info!("Loaded {} scenes from {:?}", data.scenes.len(), path);
|
||||
Ok(Self { data })
|
||||
}
|
||||
|
||||
pub fn scene_count(&self) -> usize {
|
||||
self.data.scenes.len()
|
||||
}
|
||||
|
||||
pub fn get_scene_boundaries(&self) -> Vec<u64> {
|
||||
self.data.scenes.iter().map(|s| s.start_frame).collect()
|
||||
}
|
||||
|
||||
pub fn get_current_scene(&self, frame: u64) -> Option<&Scene> {
|
||||
self.data
|
||||
.scenes
|
||||
.iter()
|
||||
.find(|s| frame >= s.start_frame && frame <= s.end_frame)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
//! Overlay module
|
||||
//!
|
||||
//! ASR subtitle and YOLO bbox overlay management
|
||||
//! ASR subtitle, YOLO bbox, and chunk marker overlay management
|
||||
|
||||
pub mod asr;
|
||||
pub mod chunk;
|
||||
pub mod yolo;
|
||||
|
||||
pub use asr::AsrLoader;
|
||||
pub use chunk::ChunkLoader;
|
||||
pub use yolo::YoloLoader;
|
||||
|
||||
Reference in New Issue
Block a user