gif color count slider (2-256) and dithering control in editing screen, both wired through export/preview pipeline
This commit is contained in:
@@ -40,6 +40,7 @@ pub struct TranscodeRequest {
|
|||||||
pub scratch_dir: PathBuf,
|
pub scratch_dir: PathBuf,
|
||||||
pub crop: Option<CaptureRect>,
|
pub crop: Option<CaptureRect>,
|
||||||
pub gif_budget_mode: GifBudgetMode,
|
pub gif_budget_mode: GifBudgetMode,
|
||||||
|
pub gif_colors: u16,
|
||||||
pub deleted_frame_indices: Vec<u32>,
|
pub deleted_frame_indices: Vec<u32>,
|
||||||
pub trim_start_secs: Option<f64>,
|
pub trim_start_secs: Option<f64>,
|
||||||
pub trim_end_secs: Option<f64>,
|
pub trim_end_secs: Option<f64>,
|
||||||
@@ -353,12 +354,13 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
|||||||
.map(|s| format!("{s},"))
|
.map(|s| format!("{s},"))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let palettegen_filter = format!(
|
let palettegen_filter = format!(
|
||||||
"{cprefix}{kprefix}fps={fps},{sprefix}scale={w}:-1:flags=lanczos,palettegen=stats_mode=diff",
|
"{cprefix}{kprefix}fps={fps},{sprefix}scale={w}:-1:flags=lanczos,palettegen=stats_mode=diff:max_colors={colors}",
|
||||||
cprefix = crop_prefix,
|
cprefix = crop_prefix,
|
||||||
kprefix = click_prefix,
|
kprefix = click_prefix,
|
||||||
sprefix = select_prefix,
|
sprefix = select_prefix,
|
||||||
fps = effective_fps,
|
fps = effective_fps,
|
||||||
w = scale_width,
|
w = scale_width,
|
||||||
|
colors = req.gif_colors,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut gen = Command::new(ffmpeg);
|
let mut gen = Command::new(ffmpeg);
|
||||||
@@ -749,6 +751,7 @@ mod tests {
|
|||||||
scratch_dir: PathBuf::new(),
|
scratch_dir: PathBuf::new(),
|
||||||
crop: None,
|
crop: None,
|
||||||
gif_budget_mode: GifBudgetMode::Balanced,
|
gif_budget_mode: GifBudgetMode::Balanced,
|
||||||
|
gif_colors: 256,
|
||||||
deleted_frame_indices: vec![],
|
deleted_frame_indices: vec![],
|
||||||
trim_start_secs: None,
|
trim_start_secs: None,
|
||||||
trim_end_secs: None,
|
trim_end_secs: None,
|
||||||
|
|||||||
+11
-1
@@ -644,6 +644,10 @@ pub struct ExportRequest {
|
|||||||
pub crop: Option<CaptureRect>,
|
pub crop: Option<CaptureRect>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub gif_budget_mode: GifBudgetMode,
|
pub gif_budget_mode: GifBudgetMode,
|
||||||
|
#[serde(default)]
|
||||||
|
pub gif_dither: Option<GifDither>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub gif_colors: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -666,6 +670,10 @@ pub struct PreviewRequest {
|
|||||||
pub target_bytes: u64,
|
pub target_bytes: u64,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub gif_budget_mode: GifBudgetMode,
|
pub gif_budget_mode: GifBudgetMode,
|
||||||
|
#[serde(default)]
|
||||||
|
pub gif_dither: Option<GifDither>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub gif_colors: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -691,6 +699,7 @@ fn render_preview(
|
|||||||
fps: request.fps,
|
fps: request.fps,
|
||||||
keep_audio: false,
|
keep_audio: false,
|
||||||
gif_dither: GifDither::FloydSteinberg,
|
gif_dither: GifDither::FloydSteinberg,
|
||||||
|
gif_colors: request.gif_colors.unwrap_or(256),
|
||||||
webm_codec: WebmCodec::Vp9,
|
webm_codec: WebmCodec::Vp9,
|
||||||
mp4_codec: Mp4Codec::H264,
|
mp4_codec: Mp4Codec::H264,
|
||||||
scratch_dir: PathBuf::new(),
|
scratch_dir: PathBuf::new(),
|
||||||
@@ -1286,7 +1295,8 @@ fn export(app: AppHandle, state: State<'_, AppState>, request: ExportRequest) ->
|
|||||||
duration_secs: effective_duration,
|
duration_secs: effective_duration,
|
||||||
fps: request.fps,
|
fps: request.fps,
|
||||||
keep_audio: request.keep_audio,
|
keep_audio: request.keep_audio,
|
||||||
gif_dither: cfg.export.gif_dither,
|
gif_dither: request.gif_dither.unwrap_or(cfg.export.gif_dither),
|
||||||
|
gif_colors: request.gif_colors.unwrap_or(256),
|
||||||
webm_codec: cfg.export.webm_codec,
|
webm_codec: cfg.export.webm_codec,
|
||||||
mp4_codec: cfg.export.mp4_codec,
|
mp4_codec: cfg.export.mp4_codec,
|
||||||
scratch_dir: temp_dir(&state.app_dir),
|
scratch_dir: temp_dir(&state.app_dir),
|
||||||
|
|||||||
+38
-2
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import { api, convertFileSrc, formatBytes, type Config, type Format, type GifBudgetMode, type RecordedClip, type ExportResult, type CaptureRect } from "./api"
|
import { api, convertFileSrc, formatBytes, type Config, type Format, type GifBudgetMode, type GifDither, type RecordedClip, type ExportResult, type CaptureRect } from "./api"
|
||||||
import { save } from "@tauri-apps/plugin-dialog"
|
import { save } from "@tauri-apps/plugin-dialog"
|
||||||
import { emit } from "@tauri-apps/api/event"
|
import { emit } from "@tauri-apps/api/event"
|
||||||
|
|
||||||
@@ -25,6 +25,8 @@
|
|||||||
let pathOverridden: boolean = $state(false)
|
let pathOverridden: boolean = $state(false)
|
||||||
|
|
||||||
let gifBudgetMode: GifBudgetMode = $state("balanced")
|
let gifBudgetMode: GifBudgetMode = $state("balanced")
|
||||||
|
let gifDither: GifDither = $state("floyd_steinberg")
|
||||||
|
let gifColors: number = $state(256)
|
||||||
|
|
||||||
// Post-record crop
|
// Post-record crop
|
||||||
let cropEnabled: boolean = $state(false)
|
let cropEnabled: boolean = $state(false)
|
||||||
@@ -114,6 +116,7 @@
|
|||||||
format = config.export.default_format
|
format = config.export.default_format
|
||||||
fps = config.capture.default_fps
|
fps = config.capture.default_fps
|
||||||
keepAudio = config.capture.capture_audio
|
keepAudio = config.capture.capture_audio
|
||||||
|
gifDither = config.export.gif_dither
|
||||||
|
|
||||||
unlistenHotkey = await api.onHotkey((kind) => {
|
unlistenHotkey = await api.onHotkey((kind) => {
|
||||||
if (kind === "start" && phase === "idle") void startRec()
|
if (kind === "start" && phase === "idle") void startRec()
|
||||||
@@ -205,7 +208,7 @@
|
|||||||
if (!clip) return
|
if (!clip) return
|
||||||
previewLoading = true
|
previewLoading = true
|
||||||
try {
|
try {
|
||||||
previewPath = await api.renderPreview(format, fps, Math.round(targetMB * 1_048_576), format === "gif" ? gifBudgetMode : undefined)
|
previewPath = await api.renderPreview(format, fps, Math.round(targetMB * 1_048_576), format === "gif" ? gifBudgetMode : undefined, format === "gif" ? gifDither : undefined, format === "gif" ? gifColors : undefined)
|
||||||
previewCacheBust = Date.now()
|
previewCacheBust = Date.now()
|
||||||
} catch { previewPath = null }
|
} catch { previewPath = null }
|
||||||
finally { previewLoading = false }
|
finally { previewLoading = false }
|
||||||
@@ -249,6 +252,8 @@
|
|||||||
output_path: outputPath.trim() || null,
|
output_path: outputPath.trim() || null,
|
||||||
crop,
|
crop,
|
||||||
gif_budget_mode: format === "gif" ? gifBudgetMode : undefined,
|
gif_budget_mode: format === "gif" ? gifBudgetMode : undefined,
|
||||||
|
gif_dither: format === "gif" ? gifDither : undefined,
|
||||||
|
gif_colors: format === "gif" ? gifColors : undefined,
|
||||||
})
|
})
|
||||||
exportResult = result; phase = "done"
|
exportResult = result; phase = "done"
|
||||||
} catch (e) { errMsg = String(e); phase = "editing" }
|
} catch (e) { errMsg = String(e); phase = "editing" }
|
||||||
@@ -652,6 +657,37 @@
|
|||||||
"Balances resolution and FPS"}
|
"Balances resolution and FPS"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<span class="section-title">Colors</span>
|
||||||
|
<div class="control-head">
|
||||||
|
<input
|
||||||
|
type="range"
|
||||||
|
class="styled-range"
|
||||||
|
min={2}
|
||||||
|
max={256}
|
||||||
|
step={1}
|
||||||
|
bind:value={gifColors}
|
||||||
|
onchange={refreshPreview}
|
||||||
|
/>
|
||||||
|
<span class="mono" style="min-width:32px;text-align:right">{gifColors}</span>
|
||||||
|
</div>
|
||||||
|
<p class="estimate">{gifColors <= 32 ? "Low - small file, posterized" : gifColors <= 128 ? "Medium - balanced" : "High - full color"}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<span class="section-title">Dithering</span>
|
||||||
|
<div class="fmt-bar">
|
||||||
|
{#each (["floyd_steinberg", "bayer", "none"] as const) as d}
|
||||||
|
<button
|
||||||
|
class="fmt-chip"
|
||||||
|
class:active={gifDither === d}
|
||||||
|
onclick={() => { gifDither = d; refreshPreview() }}
|
||||||
|
>{d === "floyd_steinberg" ? "Floyd-Steinberg" : d === "bayer" ? "Bayer" : "None"}</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
<p class="estimate">{gifDither === "floyd_steinberg" ? "Smooth gradients, slightly larger" : gifDither === "bayer" ? "Patterned, smaller file" : "No dithering, smallest file"}</p>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- FPS + Audio -->
|
<!-- FPS + Audio -->
|
||||||
|
|||||||
+4
-2
@@ -116,6 +116,8 @@ export type ExportRequest = {
|
|||||||
output_path?: string | null
|
output_path?: string | null
|
||||||
crop?: CaptureRect | null
|
crop?: CaptureRect | null
|
||||||
gif_budget_mode?: GifBudgetMode
|
gif_budget_mode?: GifBudgetMode
|
||||||
|
gif_dither?: GifDither
|
||||||
|
gif_colors?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExportResult = {
|
export type ExportResult = {
|
||||||
@@ -165,8 +167,8 @@ export const api = {
|
|||||||
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
|
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
|
||||||
extractThumbnails: (fps: number) =>
|
extractThumbnails: (fps: number) =>
|
||||||
invoke<string[]>("extract_thumbnails", { fps }),
|
invoke<string[]>("extract_thumbnails", { fps }),
|
||||||
renderPreview: (format: Format, fps: number, target_bytes: number, gif_budget_mode?: GifBudgetMode) =>
|
renderPreview: (format: Format, fps: number, target_bytes: number, gif_budget_mode?: GifBudgetMode, gif_dither?: GifDither, gif_colors?: number) =>
|
||||||
invoke<string>("render_preview", { request: { format, fps, target_bytes, gif_budget_mode } }),
|
invoke<string>("render_preview", { request: { format, fps, target_bytes, gif_budget_mode, gif_dither, gif_colors } }),
|
||||||
defaultOutputPath: (format: Format) =>
|
defaultOutputPath: (format: Format) =>
|
||||||
invoke<string>("default_output_path", { format }),
|
invoke<string>("default_output_path", { format }),
|
||||||
openUrl: (url: string) => invoke<void>("open_url", { url }),
|
openUrl: (url: string) => invoke<void>("open_url", { url }),
|
||||||
|
|||||||
Reference in New Issue
Block a user