trim scrubber
This commit is contained in:
+21
-3
@@ -24,6 +24,19 @@ pub struct TranscodeRequest {
|
|||||||
pub scratch_dir: PathBuf,
|
pub scratch_dir: PathBuf,
|
||||||
pub crop: Option<CaptureRect>,
|
pub crop: Option<CaptureRect>,
|
||||||
pub deleted_frame_indices: Vec<u32>,
|
pub deleted_frame_indices: Vec<u32>,
|
||||||
|
pub trim_start_secs: Option<f64>,
|
||||||
|
pub trim_end_secs: Option<f64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_trim(cmd: &mut Command, req: &TranscodeRequest) {
|
||||||
|
if let Some(start) = req.trim_start_secs {
|
||||||
|
if start > 0.001 {
|
||||||
|
cmd.args(["-ss", &format!("{start}")]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if let Some(end) = req.trim_end_secs {
|
||||||
|
cmd.args(["-to", &format!("{end}")]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_filter_for_deleted(deleted: &[u32]) -> Option<String> {
|
fn select_filter_for_deleted(deleted: &[u32]) -> Option<String> {
|
||||||
@@ -122,6 +135,7 @@ fn two_pass_video(
|
|||||||
.arg("-hide_banner")
|
.arg("-hide_banner")
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(&req.input);
|
.arg(&req.input);
|
||||||
|
apply_trim(&mut pass1, req);
|
||||||
if let Some(c) = &crop {
|
if let Some(c) = &crop {
|
||||||
pass1.args(["-vf", c]);
|
pass1.args(["-vf", c]);
|
||||||
}
|
}
|
||||||
@@ -141,6 +155,7 @@ fn two_pass_video(
|
|||||||
.arg("-hide_banner")
|
.arg("-hide_banner")
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(&req.input);
|
.arg(&req.input);
|
||||||
|
apply_trim(&mut pass2, req);
|
||||||
if let Some(c) = &crop {
|
if let Some(c) = &crop {
|
||||||
pass2.args(["-vf", c]);
|
pass2.args(["-vf", c]);
|
||||||
}
|
}
|
||||||
@@ -205,8 +220,9 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
|||||||
gen.arg("-y")
|
gen.arg("-y")
|
||||||
.arg("-hide_banner")
|
.arg("-hide_banner")
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(&req.input)
|
.arg(&req.input);
|
||||||
.args(["-vf", &palettegen_filter])
|
apply_trim(&mut gen, req);
|
||||||
|
gen.args(["-vf", &palettegen_filter])
|
||||||
.arg(&palette_path);
|
.arg(&palette_path);
|
||||||
run(&mut gen, "gif palette generation")?;
|
run(&mut gen, "gif palette generation")?;
|
||||||
|
|
||||||
@@ -229,7 +245,9 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
|||||||
.arg("-y")
|
.arg("-y")
|
||||||
.arg("-hide_banner")
|
.arg("-hide_banner")
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(&req.input)
|
.arg(&req.input);
|
||||||
|
apply_trim(&mut encode, req);
|
||||||
|
encode
|
||||||
.arg("-i")
|
.arg("-i")
|
||||||
.arg(&palette_path)
|
.arg(&palette_path)
|
||||||
.args(["-lavfi", &use_filter])
|
.args(["-lavfi", &use_filter])
|
||||||
|
|||||||
+18
-1
@@ -368,6 +368,10 @@ pub struct ExportRequest {
|
|||||||
pub keep_audio: bool,
|
pub keep_audio: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub deleted_frame_indices: Vec<u32>,
|
pub deleted_frame_indices: Vec<u32>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub trim_start_secs: Option<f64>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub trim_end_secs: Option<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -478,12 +482,23 @@ fn export(state: State<'_, AppState>, request: ExportRequest) -> Result<ExportRe
|
|||||||
ext_for(request.format)
|
ext_for(request.format)
|
||||||
));
|
));
|
||||||
|
|
||||||
|
let trim_start = request.trim_start_secs.filter(|s| *s > 0.001);
|
||||||
|
let trim_end = request
|
||||||
|
.trim_end_secs
|
||||||
|
.filter(|e| *e < clip.duration_secs - 0.001);
|
||||||
|
let effective_duration = match (trim_start, trim_end) {
|
||||||
|
(Some(s), Some(e)) => (e - s).max(0.1),
|
||||||
|
(Some(s), None) => (clip.duration_secs - s).max(0.1),
|
||||||
|
(None, Some(e)) => e.max(0.1),
|
||||||
|
(None, None) => clip.duration_secs,
|
||||||
|
};
|
||||||
|
|
||||||
let req = encode::TranscodeRequest {
|
let req = encode::TranscodeRequest {
|
||||||
input: clip.temp_path.clone(),
|
input: clip.temp_path.clone(),
|
||||||
output: out_path.clone(),
|
output: out_path.clone(),
|
||||||
format: request.format,
|
format: request.format,
|
||||||
target_bytes: request.target_bytes,
|
target_bytes: request.target_bytes,
|
||||||
duration_secs: clip.duration_secs,
|
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: cfg.export.gif_dither,
|
||||||
@@ -492,6 +507,8 @@ fn export(state: State<'_, AppState>, request: ExportRequest) -> Result<ExportRe
|
|||||||
scratch_dir: temp_dir(&state.app_dir),
|
scratch_dir: temp_dir(&state.app_dir),
|
||||||
crop: clip.crop,
|
crop: clip.crop,
|
||||||
deleted_frame_indices: request.deleted_frame_indices,
|
deleted_frame_indices: request.deleted_frame_indices,
|
||||||
|
trim_start_secs: trim_start,
|
||||||
|
trim_end_secs: trim_end,
|
||||||
};
|
};
|
||||||
|
|
||||||
encode::transcode(&ffmpeg, &req).map_err(|e| format!("{e:#}"))?;
|
encode::transcode(&ffmpeg, &req).map_err(|e| format!("{e:#}"))?;
|
||||||
|
|||||||
@@ -30,6 +30,8 @@
|
|||||||
let thumbnails: string[] = $state([])
|
let thumbnails: string[] = $state([])
|
||||||
let deletedFrames: Set<number> = $state(new Set())
|
let deletedFrames: Set<number> = $state(new Set())
|
||||||
let loadingThumbs: boolean = $state(false)
|
let loadingThumbs: boolean = $state(false)
|
||||||
|
let trimStart: number = $state(0)
|
||||||
|
let trimEnd: number = $state(0)
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
config = await api.getConfig()
|
config = await api.getConfig()
|
||||||
@@ -95,6 +97,8 @@
|
|||||||
phase = "editing"
|
phase = "editing"
|
||||||
const sensible = Math.max(1, Math.round(c.duration_secs * 0.5))
|
const sensible = Math.max(1, Math.round(c.duration_secs * 0.5))
|
||||||
targetMB = Math.min(50, Math.max(minMB(c.duration_secs), sensible))
|
targetMB = Math.min(50, Math.max(minMB(c.duration_secs), sensible))
|
||||||
|
trimStart = 0
|
||||||
|
trimEnd = c.duration_secs
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errMsg = String(e)
|
errMsg = String(e)
|
||||||
phase = "idle"
|
phase = "idle"
|
||||||
@@ -159,17 +163,23 @@
|
|||||||
deletedFrames = new Set()
|
deletedFrames = new Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let trimmedDuration = $derived(Math.max(0.1, trimEnd - trimStart))
|
||||||
|
|
||||||
async function doExport() {
|
async function doExport() {
|
||||||
if (!clip) return
|
if (!clip) return
|
||||||
errMsg = null
|
errMsg = null
|
||||||
phase = "exporting"
|
phase = "exporting"
|
||||||
try {
|
try {
|
||||||
|
const tsStart = trimStart > 0.05 ? trimStart : null
|
||||||
|
const tsEnd = trimEnd < clip.duration_secs - 0.05 ? trimEnd : null
|
||||||
const result = await api.export({
|
const result = await api.export({
|
||||||
format,
|
format,
|
||||||
target_bytes: Math.round(targetMB * 1_048_576),
|
target_bytes: Math.round(targetMB * 1_048_576),
|
||||||
fps,
|
fps,
|
||||||
keep_audio: keepAudio && format !== "gif",
|
keep_audio: keepAudio && format !== "gif",
|
||||||
deleted_frame_indices: format === "gif" ? Array.from(deletedFrames) : [],
|
deleted_frame_indices: format === "gif" ? Array.from(deletedFrames) : [],
|
||||||
|
trim_start_secs: tsStart,
|
||||||
|
trim_end_secs: tsEnd,
|
||||||
})
|
})
|
||||||
exportResult = result
|
exportResult = result
|
||||||
phase = "done"
|
phase = "done"
|
||||||
@@ -254,6 +264,51 @@
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section class="export">
|
<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>
|
<h2>export</h2>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@@ -577,6 +632,23 @@
|
|||||||
color: #888;
|
color: #888;
|
||||||
font-size: 0.85rem;
|
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 {
|
.frames {
|
||||||
margin: 1rem 0;
|
margin: 1rem 0;
|
||||||
padding: 0.75rem;
|
padding: 0.75rem;
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ export type ExportRequest = {
|
|||||||
fps: number
|
fps: number
|
||||||
keep_audio: boolean
|
keep_audio: boolean
|
||||||
deleted_frame_indices: number[]
|
deleted_frame_indices: number[]
|
||||||
|
trim_start_secs?: number | null
|
||||||
|
trim_end_secs?: number | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExportResult = {
|
export type ExportResult = {
|
||||||
|
|||||||
Reference in New Issue
Block a user