20 fixes: mutex poisoning recovery, clickthrough shutdown, audio cleanup, config corruption, GIF aspect ratio, ffmpeg crash detection, cancel export, discard confirm, thumbnail cache, keyboard nav, right-click tracking, multi-monitor overlay, click injection fix, update script robustness, effect cleanup, concat guard, dead code removal
This commit is contained in:
+21
-8
@@ -43,6 +43,8 @@ pub struct TranscodeRequest {
|
||||
pub trim_start_secs: Option<f64>,
|
||||
pub trim_end_secs: Option<f64>,
|
||||
pub clicks: Vec<Click>,
|
||||
pub clip_width: u32,
|
||||
pub clip_height: u32,
|
||||
/// Optional channel to report encoding progress.
|
||||
#[doc(hidden)]
|
||||
pub progress_tx: Option<Sender<EncodeProgress>>,
|
||||
@@ -70,8 +72,13 @@ fn click_filters(req: &TranscodeRequest) -> Option<String> {
|
||||
let y = click.y - half;
|
||||
let t1 = (click.time_secs - 0.05).max(0.0);
|
||||
let t2 = click.time_secs + 0.25;
|
||||
let color = match click.button {
|
||||
crate::clicks::MouseButton::Left => "yellow@0.6",
|
||||
crate::clicks::MouseButton::Right => "blue@0.6",
|
||||
crate::clicks::MouseButton::Middle => "green@0.6",
|
||||
};
|
||||
parts.push(format!(
|
||||
"drawbox=x={x}:y={y}:w={size}:h={size}:color=yellow@0.6:t=fill:enable='between(t,{t1:.3},{t2:.3})'"
|
||||
"drawbox=x={x}:y={y}:w={size}:h={size}:color={color}:t=fill:enable='between(t,{t1:.3},{t2:.3})'"
|
||||
));
|
||||
}
|
||||
if parts.is_empty() {
|
||||
@@ -334,7 +341,7 @@ fn cleanup_pass_logs(stem: &Path) {
|
||||
|
||||
fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
||||
let palette_path = req.scratch_dir.join("palette.png");
|
||||
let scale_width = estimate_gif_scale_width(req);
|
||||
let scale_width = estimate_gif_scale_width(req, req.clip_width, req.clip_height);
|
||||
let crop_prefix = crop_filter(req.crop)
|
||||
.map(|c| format!("{c},"))
|
||||
.unwrap_or_default();
|
||||
@@ -405,11 +412,11 @@ fn encode_gif(ffmpeg: &Path, req: &TranscodeRequest) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn estimate_gif_scale_width(req: &TranscodeRequest) -> u32 {
|
||||
fn estimate_gif_scale_width(req: &TranscodeRequest, clip_width: u32, clip_height: u32) -> u32 {
|
||||
let bytes_per_pixel_per_frame = 0.5_f64;
|
||||
let frames = (req.fps as f64 * req.duration_secs).max(1.0);
|
||||
let budget = req.target_bytes as f64 / (frames * bytes_per_pixel_per_frame);
|
||||
let aspect = 16.0_f64 / 9.0;
|
||||
let aspect = if clip_height > 0 { clip_width as f64 / clip_height as f64 } else { 16.0 / 9.0 };
|
||||
let w = (budget * aspect).sqrt();
|
||||
let w = w.clamp(120.0, 1280.0).round() as u32;
|
||||
(w / 2) * 2
|
||||
@@ -536,6 +543,11 @@ pub fn concat_pcm(segments: &[PathBuf], output: &Path) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct TempFileGuard(PathBuf);
|
||||
impl Drop for TempFileGuard {
|
||||
fn drop(&mut self) { let _ = std::fs::remove_file(&self.0); }
|
||||
}
|
||||
|
||||
pub fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Result<()> {
|
||||
if segments.is_empty() {
|
||||
bail!("no segments to concatenate");
|
||||
@@ -551,6 +563,7 @@ pub fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Re
|
||||
std::fs::create_dir_all(parent).context("creating output parent dir")?;
|
||||
|
||||
let list_path = parent.join("concat-list.txt");
|
||||
let _guard = TempFileGuard(list_path.clone());
|
||||
let mut body = String::new();
|
||||
for seg in segments {
|
||||
let s = seg
|
||||
@@ -570,9 +583,7 @@ pub fn concat_segments(ffmpeg: &Path, segments: &[PathBuf], output: &Path) -> Re
|
||||
.arg(&list_path)
|
||||
.args(["-c", "copy"])
|
||||
.arg(output);
|
||||
let result = run(&mut cmd, "concat");
|
||||
let _ = std::fs::remove_file(&list_path);
|
||||
result
|
||||
run(&mut cmd, "concat")
|
||||
}
|
||||
|
||||
fn run(cmd: &mut Command, label: &str) -> Result<()> {
|
||||
@@ -706,6 +717,8 @@ mod tests {
|
||||
trim_start_secs: None,
|
||||
trim_end_secs: None,
|
||||
clicks: vec![],
|
||||
clip_width: 1920,
|
||||
clip_height: 1080,
|
||||
progress_tx: None,
|
||||
}
|
||||
}
|
||||
@@ -780,7 +793,7 @@ mod tests {
|
||||
#[test]
|
||||
fn click_filters_capped_at_max() {
|
||||
let clicks: Vec<Click> = (0..100)
|
||||
.map(|i| Click { time_secs: i as f64, x: i, y: i })
|
||||
.map(|i| Click { time_secs: i as f64, x: i, y: i, button: crate::clicks::MouseButton::Left })
|
||||
.collect();
|
||||
let req = TranscodeRequest {
|
||||
clicks,
|
||||
|
||||
Reference in New Issue
Block a user