From 7bbc5e0393b03b0a79ebc2c8026d48a060483ef0 Mon Sep 17 00:00:00 2001 From: uku Date: Fri, 11 Jul 2025 10:20:45 +0200 Subject: [PATCH] fix(windows): don't open terminal windows when runnings commands --- src/ffmpeg.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/ffmpeg.rs b/src/ffmpeg.rs index f79af81..f314661 100644 --- a/src/ffmpeg.rs +++ b/src/ffmpeg.rs @@ -14,6 +14,40 @@ use tokio::{ use crate::ProgressMessage; +trait CommandExt { + fn create_no_window(&mut self) -> &mut Self; +} + +impl CommandExt for Command { + #[cfg(windows)] + fn create_no_window(&mut self) -> &mut Self { + use std::os::windows::process::CommandExt as _; + + // https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags#flags + self.creation_flags(0x0800_0000) + } + + #[cfg(not(windows))] + fn create_no_window(&mut self) -> &mut Self { + self + } +} + +impl CommandExt for std::process::Command { + #[cfg(windows)] + fn create_no_window(&mut self) -> &mut Self { + use std::os::windows::process::CommandExt as _; + + // https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags#flags + self.creation_flags(0x0800_0000) + } + + #[cfg(not(windows))] + fn create_no_window(&mut self) -> &mut Self { + self + } +} + #[derive(serde::Deserialize)] struct FfprobeOut { streams: Vec, @@ -59,10 +93,12 @@ impl From for Codec { pub fn check() -> Result<()> { std::process::Command::new("ffmpeg") + .create_no_window() .output() .context("could not find ffmpeg")?; std::process::Command::new("ffprobe") + .create_no_window() .output() .context("could not find ffprobe")?; @@ -81,6 +117,7 @@ pub async fn get_video_meta(path: &Path) -> Result { ]) .arg(path) .stdout(Stdio::piped()) + .create_no_window() .output() .await?; @@ -151,6 +188,7 @@ pub async fn convert_video( .args(["-y", "-loglevel", "error", "-progress", "-", "-nostats"]) .arg(&out_path) .stdout(Stdio::piped()) + .create_no_window() .spawn()?; let stdout = child.stdout.take().unwrap();