Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix: suppress console windows when spawning ffmpeg on Windows

Jareer195f0694b2b7
diff --git a/desktop/src-tauri/src/lib.rs b/desktop/src-tauri/src/lib.rs
index 72031b00..57180d0b 100644
--- a/desktop/src-tauri/src/lib.rs
+++ b/desktop/src-tauri/src/lib.rs
@@ -360,7 +360,7 @@ fn filmstrip(path: &str, count: u32, height: u32) -> Result<Vec<u8>, String> {
.filter(|seconds| *seconds > 0.0)
.ok_or_else(|| format!("{path} reports no duration"))?;
- let output = std::process::Command::new(wolfcut_media::ffmpeg())
+ let output = wolfcut_media::command(wolfcut_media::ffmpeg())
.args(["-hide_banner", "-nostdin", "-loglevel", "error"])
.args(["-i", path])
.args([
@@ -467,7 +467,7 @@ fn poster_frame(project: &str) -> Result<Vec<u8>, String> {
return Err("nothing on the timeline to preview".to_owned());
};
- let mut command = std::process::Command::new(wolfcut_media::ffmpeg());
+ let mut command = wolfcut_media::command(wolfcut_media::ffmpeg());
command.args(["-hide_banner", "-nostdin", "-loglevel", "error"]);
// Seeking a still means seeking a one-frame stream to nowhere.
if !is_still && source_start > 0.0 {
diff --git a/desktop/src-tauri/src/playback.rs b/desktop/src-tauri/src/playback.rs
index e127ff26..0eb755c5 100644
--- a/desktop/src-tauri/src/playback.rs
+++ b/desktop/src-tauri/src/playback.rs
@@ -609,7 +609,7 @@ fn decode(spec: &ClipSpec, project: &Path, key: &str) -> Result<Pcm, String> {
let file = std::fs::File::create(&temporary)
.map_err(|error| format!("could not create {}: {error}", temporary.display()))?;
- let status = std::process::Command::new(wolfcut_media::ffmpeg())
+ let status = wolfcut_media::command(wolfcut_media::ffmpeg())
.args(["-hide_banner", "-nostdin", "-loglevel", "error"])
.args(["-ss", &format!("{:.6}", spec.source_start)])
.args(["-t", &format!("{window:.6}")])
diff --git a/desktop/src-tauri/src/transcribe.rs b/desktop/src-tauri/src/transcribe.rs
index 4bc9bc5d..f8a7ce6a 100644
--- a/desktop/src-tauri/src/transcribe.rs
+++ b/desktop/src-tauri/src/transcribe.rs
@@ -453,7 +453,7 @@ fn extract_wav(
destination: &Path,
slot: &Arc<Mutex<Option<Child>>>,
) -> Result<(), String> {
- let mut command = Command::new(wolfcut_media::ffmpeg());
+ let mut command = wolfcut_media::command(wolfcut_media::ffmpeg());
command
.args(["-hide_banner", "-nostdin", "-loglevel", "error", "-y"])
.args(["-ss", &format!("{start:.6}")])
@@ -558,7 +558,7 @@ fn run_transcription(
.map(|count| count.get().min(8))
.unwrap_or(4);
- let mut command = Command::new(&binary);
+ let mut command = wolfcut_media::command(&binary);
command
.arg("-m")
.arg(&model)
diff --git a/engine/crates/wolfcut-media/src/lib.rs b/engine/crates/wolfcut-media/src/lib.rs
index abd479d5..b450754f 100644
--- a/engine/crates/wolfcut-media/src/lib.rs
+++ b/engine/crates/wolfcut-media/src/lib.rs
@@ -29,3 +29,4 @@ pub use error::{Error, Result};
pub use peaks::Peaks;
pub use pool::{FrameCache, ReaderPool};
pub use probe::{AudioStream, MediaInfo, VideoStream, probe};
+pub use process::command;
diff --git a/engine/crates/wolfcut-media/src/probe.rs b/engine/crates/wolfcut-media/src/probe.rs
index 540174e1..19f8f01f 100644
--- a/engine/crates/wolfcut-media/src/probe.rs
+++ b/engine/crates/wolfcut-media/src/probe.rs
@@ -1,7 +1,6 @@
//! Asking `ffprobe` what is inside a file.
use std::path::{Path, PathBuf};
-use std::process::Command;
use wolfcut_core::time::{FrameRate, Rational};
use serde_json::Value;
@@ -67,7 +66,7 @@ impl MediaInfo {
/// Runs `ffprobe` and summarises what it found.
pub fn probe(path: impl AsRef<Path>) -> Result<MediaInfo> {
let path = path.as_ref();
- let output = Command::new(crate::binaries::ffprobe())
+ let output = crate::process::command(crate::binaries::ffprobe())
.args(["-v", "error", "-show_streams", "-show_format", "-of", "json"])
.arg(path)
.output()
diff --git a/engine/crates/wolfcut-media/src/process.rs b/engine/crates/wolfcut-media/src/process.rs
index 2565a838..4af18a22 100644
--- a/engine/crates/wolfcut-media/src/process.rs
+++ b/engine/crates/wolfcut-media/src/process.rs
@@ -6,6 +6,7 @@
//! the void and leaves the user with "exited with status 1". Draining on a
//! thread also means the pipe can never fill up and stall the child.
+use std::ffi::OsStr;
use std::io::Read;
use std::path::Path;
use std::process::{Child, Command, Stdio};
@@ -18,10 +19,27 @@ use crate::error::{Error, Result};
/// little; this holds the message that matters plus its context.
const STDERR_KEEP: usize = 8 * 1024;
+/// A `Command` for `binary` that never flashes a console window.
+///
+/// On Windows, a GUI-subsystem parent has no console, so each console-subsystem
+/// child (FFmpeg, ffprobe, ...) gets a fresh one that pops up over the app.
+/// `CREATE_NO_WINDOW` suppresses that. Elsewhere this is just `Command::new`.
+pub fn command(binary: impl AsRef<OsStr>) -> Command {
+ #[allow(unused_mut)]
+ let mut command = Command::new(binary.as_ref());
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ const CREATE_NO_WINDOW: u32 = 0x0800_0000;
+ command.creation_flags(CREATE_NO_WINDOW);
+ }
+ command
+}
+
/// A command with the flags every invocation wants: no banner, no terminal
/// interaction, errors only.
pub(crate) fn base_command(binary: &Path) -> Command {
- let mut command = Command::new(binary);
+ let mut command = command(binary);
command.args(["-hide_banner", "-nostdin", "-loglevel", "error"]);
command
}