From 327b87a18acb871e18cbbe42d33cd8e9534fd4ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Sun, 11 Sep 2022 20:33:41 +0200 Subject: [PATCH] perf: correct `ffmpeg` params for efficient video previews -ss before -i ("When used as an output option (before an output url), decodes but discards input until the timestamps reach position. ") discard all non-keyframes turn off accurate seek --- src/previews/video.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/previews/video.rs b/src/previews/video.rs index 331a1d8..2b8d989 100644 --- a/src/previews/video.rs +++ b/src/previews/video.rs @@ -30,9 +30,12 @@ impl<'a> Previewable for VideoPath<'a> { let outfile = tempfile::Builder::new().suffix(".webp").tempfile()?; let thumbnail_cmd = Command::new("ffmpeg") .args(["-threads", "1"]) + .args(["-discard", "nokey"]) + .args(["-noaccurate_seek"]) + .args(["-ss", &(90f64.min(duration / 2.0)).to_string()]) .args(["-i", &self.0.to_string_lossy()]) .args(["-vframes", "1"]) - .args(["-ss", &(90f64.min(duration / 2.0)).to_string()]) + .args(["-vsync", "passthrough"]) .arg(&*outfile.path().to_string_lossy()) .arg("-y") .output()?;