static preview frame on slider release
This commit is contained in:
@@ -36,6 +36,9 @@
|
||||
let trimEnd: number = $state(0)
|
||||
let outputPath: string = $state("")
|
||||
let pathOverridden: boolean = $state(false)
|
||||
let previewPath: string | null = $state(null)
|
||||
let previewLoading: boolean = $state(false)
|
||||
let previewCacheBust: number = $state(0)
|
||||
|
||||
onMount(() => {
|
||||
let unlisten: (() => void) | null = null
|
||||
@@ -179,6 +182,24 @@
|
||||
return Math.min(200, Math.max(10, durationSecs * 5))
|
||||
}
|
||||
|
||||
async function refreshPreview() {
|
||||
if (!clip) return
|
||||
previewLoading = true
|
||||
try {
|
||||
const path = await api.renderPreview(
|
||||
format,
|
||||
fps,
|
||||
Math.round(targetMB * 1_048_576),
|
||||
)
|
||||
previewPath = path
|
||||
previewCacheBust = Date.now()
|
||||
} catch (e) {
|
||||
console.error("preview", e)
|
||||
} finally {
|
||||
previewLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadThumbnails() {
|
||||
if (format !== "gif") {
|
||||
thumbnails = []
|
||||
@@ -259,6 +280,12 @@
|
||||
}
|
||||
})
|
||||
|
||||
$effect(() => {
|
||||
if (phase === "editing" && format) {
|
||||
void refreshPreview()
|
||||
}
|
||||
})
|
||||
|
||||
function startOver() {
|
||||
clip = null
|
||||
exportResult = null
|
||||
@@ -418,6 +445,7 @@
|
||||
max={maxMB(clip.duration_secs)}
|
||||
step="0.1"
|
||||
bind:value={targetMB}
|
||||
onchange={refreshPreview}
|
||||
/>
|
||||
</label>
|
||||
<div class="readout">{targetMB.toFixed(1)} MB</div>
|
||||
@@ -426,6 +454,13 @@
|
||||
{targetMB.toFixed(1)} MB → {previewDims} at {fps}fps, {trimmedDuration.toFixed(1)}s
|
||||
</p>
|
||||
|
||||
{#if previewPath}
|
||||
<div class="preview">
|
||||
<img src={convertFileSrc(previewPath) + "?t=" + previewCacheBust} alt="preview frame" />
|
||||
{#if previewLoading}<div class="preview-overlay">rendering...</div>{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="grid-row">
|
||||
<label>
|
||||
fps
|
||||
@@ -724,6 +759,30 @@
|
||||
color: #888;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.preview {
|
||||
position: relative;
|
||||
margin: 0.75rem 0;
|
||||
background: #111;
|
||||
border: 1px solid #2a2a2a;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
.preview img {
|
||||
max-width: 100%;
|
||||
max-height: 300px;
|
||||
display: block;
|
||||
}
|
||||
.preview-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
color: #aaa;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
input[type="range"] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user