gif per-frame deletion with thumbnail strip

This commit is contained in:
2026-05-12 00:15:51 +03:00
parent 7c3ec87b55
commit 3a21d686ae
7 changed files with 258 additions and 7 deletions
+150
View File
@@ -2,6 +2,7 @@
import { onMount } from "svelte"
import {
api,
convertFileSrc,
formatBytes,
type Config,
type Format,
@@ -26,6 +27,9 @@
let exportResult: ExportResult | null = $state(null)
let errMsg: string | null = $state(null)
let useFrame: boolean = $state(false)
let thumbnails: string[] = $state([])
let deletedFrames: Set<number> = $state(new Set())
let loadingThumbs: boolean = $state(false)
onMount(async () => {
config = await api.getConfig()
@@ -127,6 +131,34 @@
return Math.min(200, Math.max(10, durationSecs * 5))
}
async function loadThumbnails() {
if (format !== "gif") {
thumbnails = []
return
}
loadingThumbs = true
try {
const paths = await api.extractThumbnails(fps)
thumbnails = paths
deletedFrames = new Set()
} catch (e) {
errMsg = String(e)
} finally {
loadingThumbs = false
}
}
function toggleThumb(idx: number) {
const next = new Set(deletedFrames)
if (next.has(idx)) next.delete(idx)
else next.add(idx)
deletedFrames = next
}
function clearDeleted() {
deletedFrames = new Set()
}
async function doExport() {
if (!clip) return
errMsg = null
@@ -137,6 +169,7 @@
target_bytes: Math.round(targetMB * 1_048_576),
fps,
keep_audio: keepAudio && format !== "gif",
deleted_frame_indices: format === "gif" ? Array.from(deletedFrames) : [],
})
exportResult = result
phase = "done"
@@ -146,11 +179,21 @@
}
}
$effect(() => {
if (phase === "editing" && format === "gif") {
void loadThumbnails()
} else if (format !== "gif") {
thumbnails = []
}
})
function startOver() {
clip = null
exportResult = null
errMsg = null
elapsed = 0
thumbnails = []
deletedFrames = new Set()
phase = "idle"
}
</script>
@@ -261,6 +304,34 @@
{/if}
</div>
{#if format === "gif"}
<div class="frames">
<div class="frames-head">
<span>frames {thumbnails.length > 0 ? `(${thumbnails.length - deletedFrames.size} kept / ${thumbnails.length})` : ""}</span>
{#if deletedFrames.size > 0}
<button class="small" onclick={clearDeleted}>clear deletions</button>
{/if}
</div>
{#if loadingThumbs}
<p class="hint">extracting frames...</p>
{:else if thumbnails.length > 0}
<div class="strip">
{#each thumbnails as path, idx}
<button
class="thumb"
class:deleted={deletedFrames.has(idx)}
onclick={() => toggleThumb(idx)}
title={deletedFrames.has(idx) ? "click to keep" : "click to delete"}
>
<img src={convertFileSrc(path)} alt={`frame ${idx + 1}`} />
<span class="idx">{idx + 1}</span>
</button>
{/each}
</div>
{/if}
</div>
{/if}
<div class="row">
<button class="primary" onclick={doExport}>export</button>
<button onclick={startOver}>discard and start over</button>
@@ -506,4 +577,83 @@
color: #888;
font-size: 0.85rem;
}
.frames {
margin: 1rem 0;
padding: 0.75rem;
background: #1e1e1e;
border: 1px solid #2a2a2a;
border-radius: 6px;
}
.frames-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0.6rem;
font-size: 0.85rem;
color: #aaa;
}
.small {
padding: 0.25rem 0.5rem;
font-size: 0.8rem;
}
.strip {
display: flex;
gap: 4px;
overflow-x: auto;
padding-bottom: 4px;
}
.strip::-webkit-scrollbar {
height: 8px;
}
.strip::-webkit-scrollbar-thumb {
background: #3a3a3a;
border-radius: 4px;
}
.thumb {
position: relative;
flex: 0 0 auto;
padding: 0;
border: 2px solid transparent;
border-radius: 3px;
background: transparent;
cursor: pointer;
}
.thumb img {
display: block;
width: 80px;
height: auto;
border-radius: 2px;
}
.thumb:hover {
border-color: #4a8;
}
.thumb.deleted img {
opacity: 0.25;
filter: grayscale(1);
}
.thumb.deleted {
border-color: #c33;
}
.thumb.deleted::after {
content: "×";
position: absolute;
inset: 0;
display: grid;
place-items: center;
color: #c33;
font-size: 1.6rem;
font-weight: bold;
pointer-events: none;
}
.thumb .idx {
position: absolute;
bottom: 2px;
right: 2px;
background: rgba(0, 0, 0, 0.7);
color: #ccc;
padding: 0 4px;
border-radius: 2px;
font-size: 0.7rem;
font-variant-numeric: tabular-nums;
}
</style>
+6 -1
View File
@@ -1,6 +1,8 @@
import { invoke } from "@tauri-apps/api/core"
import { invoke, convertFileSrc } from "@tauri-apps/api/core"
import { listen, type UnlistenFn } from "@tauri-apps/api/event"
export { convertFileSrc }
export type FfmpegStatus = "ready" | "missing"
export type AppStatus = {
@@ -73,6 +75,7 @@ export type ExportRequest = {
target_bytes: number
fps: number
keep_audio: boolean
deleted_frame_indices: number[]
}
export type ExportResult = {
@@ -97,6 +100,8 @@ export const api = {
showOverlay: () => invoke<void>("show_overlay"),
hideOverlay: () => invoke<void>("hide_overlay"),
getOverlayRect: () => invoke<CaptureRect>("get_overlay_rect"),
extractThumbnails: (fps: number) =>
invoke<string[]>("extract_thumbnails", { fps }),
}
export function formatBytes(n: number): string {