trim scrubber
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
let thumbnails: string[] = $state([])
|
||||
let deletedFrames: Set<number> = $state(new Set())
|
||||
let loadingThumbs: boolean = $state(false)
|
||||
let trimStart: number = $state(0)
|
||||
let trimEnd: number = $state(0)
|
||||
|
||||
onMount(async () => {
|
||||
config = await api.getConfig()
|
||||
@@ -95,6 +97,8 @@
|
||||
phase = "editing"
|
||||
const sensible = Math.max(1, Math.round(c.duration_secs * 0.5))
|
||||
targetMB = Math.min(50, Math.max(minMB(c.duration_secs), sensible))
|
||||
trimStart = 0
|
||||
trimEnd = c.duration_secs
|
||||
} catch (e) {
|
||||
errMsg = String(e)
|
||||
phase = "idle"
|
||||
@@ -159,17 +163,23 @@
|
||||
deletedFrames = new Set()
|
||||
}
|
||||
|
||||
let trimmedDuration = $derived(Math.max(0.1, trimEnd - trimStart))
|
||||
|
||||
async function doExport() {
|
||||
if (!clip) return
|
||||
errMsg = null
|
||||
phase = "exporting"
|
||||
try {
|
||||
const tsStart = trimStart > 0.05 ? trimStart : null
|
||||
const tsEnd = trimEnd < clip.duration_secs - 0.05 ? trimEnd : null
|
||||
const result = await api.export({
|
||||
format,
|
||||
target_bytes: Math.round(targetMB * 1_048_576),
|
||||
fps,
|
||||
keep_audio: keepAudio && format !== "gif",
|
||||
deleted_frame_indices: format === "gif" ? Array.from(deletedFrames) : [],
|
||||
trim_start_secs: tsStart,
|
||||
trim_end_secs: tsEnd,
|
||||
})
|
||||
exportResult = result
|
||||
phase = "done"
|
||||
@@ -254,6 +264,51 @@
|
||||
</section>
|
||||
|
||||
<section class="export">
|
||||
<h2>trim</h2>
|
||||
<div class="trim">
|
||||
<div class="trim-bar">
|
||||
<div
|
||||
class="trim-range"
|
||||
style="left: {(trimStart / clip.duration_secs) * 100}%; right: {(1 - trimEnd / clip.duration_secs) * 100}%"
|
||||
></div>
|
||||
</div>
|
||||
<div class="slider-row">
|
||||
<label>
|
||||
start
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max={clip.duration_secs}
|
||||
step="0.05"
|
||||
value={trimStart}
|
||||
oninput={(e) => {
|
||||
const v = parseFloat((e.currentTarget as HTMLInputElement).value)
|
||||
trimStart = Math.min(v, trimEnd - 0.1)
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<div class="readout">{trimStart.toFixed(2)}s</div>
|
||||
</div>
|
||||
<div class="slider-row">
|
||||
<label>
|
||||
end
|
||||
<input
|
||||
type="range"
|
||||
min="0"
|
||||
max={clip.duration_secs}
|
||||
step="0.05"
|
||||
value={trimEnd}
|
||||
oninput={(e) => {
|
||||
const v = parseFloat((e.currentTarget as HTMLInputElement).value)
|
||||
trimEnd = Math.max(v, trimStart + 0.1)
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<div class="readout">{trimEnd.toFixed(2)}s</div>
|
||||
</div>
|
||||
<p class="hint">kept: {trimmedDuration.toFixed(2)}s of {clip.duration_secs.toFixed(2)}s</p>
|
||||
</div>
|
||||
|
||||
<h2>export</h2>
|
||||
|
||||
<div class="row">
|
||||
@@ -577,6 +632,23 @@
|
||||
color: #888;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
.trim {
|
||||
margin: 0.5rem 0 1.5rem;
|
||||
}
|
||||
.trim-bar {
|
||||
position: relative;
|
||||
height: 6px;
|
||||
background: #2a2a2a;
|
||||
border-radius: 3px;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
.trim-range {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
background: #4a8;
|
||||
border-radius: 3px;
|
||||
}
|
||||
.frames {
|
||||
margin: 1rem 0;
|
||||
padding: 0.75rem;
|
||||
|
||||
Reference in New Issue
Block a user