fps selector on idle screen, lower gif fps minimum, 16:9 preset, aspect ratio lock on frame resize, gif budget mode (resolution/framerate/balanced priority), fix asset protocol scope
This commit is contained in:
+33
-13
@@ -19,7 +19,7 @@ use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::bootstrap::FfmpegStatus;
|
||||
use crate::config::{Config, Format};
|
||||
use crate::config::{Config, Format, GifBudgetMode, GifDither, Mp4Codec, WebmCodec};
|
||||
|
||||
fn lock<T>(m: &std::sync::Mutex<T>) -> std::sync::MutexGuard<'_, T> {
|
||||
m.lock().unwrap_or_else(|e| e.into_inner())
|
||||
@@ -264,6 +264,7 @@ async fn download_ffmpeg(app: AppHandle, state: State<'_, AppState>) -> Result<(
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct StartCaptureRequest {
|
||||
pub crop: Option<CaptureRect>,
|
||||
pub fps: Option<u32>,
|
||||
}
|
||||
|
||||
fn segment_path(app_dir: &Path, idx: usize) -> PathBuf {
|
||||
@@ -340,7 +341,8 @@ fn start_capture(
|
||||
std::fs::create_dir_all(&temp).map_err(|e| format!("creating temp dir: {e}"))?;
|
||||
clear_temp_segments(&state.app_dir);
|
||||
|
||||
let crop = request.and_then(|r| r.crop);
|
||||
let crop = request.as_ref().and_then(|r| r.crop);
|
||||
let fps = request.as_ref().and_then(|r| r.fps).unwrap_or(cfg.capture.default_fps);
|
||||
let output = segment_path(&state.app_dir, 1);
|
||||
|
||||
let ffmpeg = bootstrap::ffmpeg_path(&state.app_dir);
|
||||
@@ -357,7 +359,7 @@ fn start_capture(
|
||||
cfg.capture.capture_cursor,
|
||||
cfg.capture.capture_audio,
|
||||
crop,
|
||||
cfg.capture.default_fps,
|
||||
fps,
|
||||
)
|
||||
.map_err(|e| format!("{e:#}"))?;
|
||||
|
||||
@@ -640,6 +642,8 @@ pub struct ExportRequest {
|
||||
pub output_path: Option<String>,
|
||||
#[serde(default)]
|
||||
pub crop: Option<CaptureRect>,
|
||||
#[serde(default)]
|
||||
pub gif_budget_mode: GifBudgetMode,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -660,6 +664,8 @@ pub struct PreviewRequest {
|
||||
pub format: Format,
|
||||
pub fps: u32,
|
||||
pub target_bytes: u64,
|
||||
#[serde(default)]
|
||||
pub gif_budget_mode: GifBudgetMode,
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -676,18 +682,31 @@ fn render_preview(
|
||||
}
|
||||
|
||||
let target_width: u32 = if request.format == Format::Gif {
|
||||
// For GIF, derive a width that fits the target byte budget.
|
||||
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 req = encode::TranscodeRequest {
|
||||
input: clip.temp_path.clone(),
|
||||
output: PathBuf::new(),
|
||||
format: request.format,
|
||||
target_bytes: request.target_bytes,
|
||||
duration_secs: clip.duration_secs,
|
||||
fps: request.fps,
|
||||
keep_audio: false,
|
||||
gif_dither: GifDither::FloydSteinberg,
|
||||
webm_codec: WebmCodec::Vp9,
|
||||
mp4_codec: Mp4Codec::H264,
|
||||
scratch_dir: PathBuf::new(),
|
||||
crop: None,
|
||||
gif_budget_mode: request.gif_budget_mode,
|
||||
deleted_frame_indices: vec![],
|
||||
trim_start_secs: None,
|
||||
trim_end_secs: None,
|
||||
clicks: vec![],
|
||||
clip_width: clip.width,
|
||||
clip_height: clip.height,
|
||||
progress_tx: None,
|
||||
};
|
||||
let w = (budget * aspect).sqrt();
|
||||
(w.clamp(120.0, clip.width as f64) as u32 / 2) * 2
|
||||
let (w, _) = encode::gif_params(&req, clip.width, clip.height);
|
||||
w
|
||||
} else {
|
||||
// For video formats, scale to a reasonable preview size.
|
||||
clip.width.min(1280).max(160)
|
||||
};
|
||||
|
||||
@@ -1272,6 +1291,7 @@ fn export(app: AppHandle, state: State<'_, AppState>, request: ExportRequest) ->
|
||||
mp4_codec: cfg.export.mp4_codec,
|
||||
scratch_dir: temp_dir(&state.app_dir),
|
||||
crop: request.crop,
|
||||
gif_budget_mode: request.gif_budget_mode,
|
||||
deleted_frame_indices: request.deleted_frame_indices,
|
||||
trim_start_secs: trim_start,
|
||||
trim_end_secs: trim_end,
|
||||
|
||||
Reference in New Issue
Block a user