static preview frame on slider release
This commit is contained in:
@@ -607,6 +607,51 @@ fn default_output_path(state: State<'_, AppState>, format: Format) -> String {
|
||||
.into_owned()
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct PreviewRequest {
|
||||
pub format: Format,
|
||||
pub fps: u32,
|
||||
pub target_bytes: u64,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn render_preview(
|
||||
state: State<'_, AppState>,
|
||||
request: PreviewRequest,
|
||||
) -> Result<PathBuf, String> {
|
||||
let clip = state
|
||||
.last_clip
|
||||
.lock()
|
||||
.expect("clip mutex")
|
||||
.clone()
|
||||
.ok_or_else(|| "no recorded clip available".to_string())?;
|
||||
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
||||
if !ffmpeg.is_file() {
|
||||
return Err("ffmpeg.exe not found".to_string());
|
||||
}
|
||||
|
||||
let target_width: u32 = match request.format {
|
||||
Format::Gif => {
|
||||
let frames = (request.fps as f64 * clip.duration_secs).max(1.0);
|
||||
let budget = (request.target_bytes as f64) / (frames * 0.5);
|
||||
let aspect = if clip.height == 0 {
|
||||
16.0 / 9.0
|
||||
} else {
|
||||
clip.width as f64 / clip.height as f64
|
||||
};
|
||||
let w = (budget * aspect).sqrt();
|
||||
(w.clamp(120.0, clip.width as f64) as u32 / 2) * 2
|
||||
}
|
||||
_ => clip.width,
|
||||
};
|
||||
|
||||
let preview_path = temp_dir(&state.app_dir).join("preview.png");
|
||||
let midpoint = (clip.duration_secs / 2.0).max(0.0);
|
||||
encode::render_preview(&ffmpeg, &clip.temp_path, &preview_path, midpoint, target_width)
|
||||
.map_err(|e| format!("{e:#}"))?;
|
||||
Ok(preview_path)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn extract_thumbnails(
|
||||
state: State<'_, AppState>,
|
||||
@@ -955,6 +1000,7 @@ pub fn run() {
|
||||
export,
|
||||
default_output_path,
|
||||
extract_thumbnails,
|
||||
render_preview,
|
||||
reveal_in_explorer,
|
||||
open_url,
|
||||
show_overlay,
|
||||
|
||||
Reference in New Issue
Block a user