Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(windows): hide ffmpeg console windows with CREATE_NO_WINDOW

Louis Beaumont825f06a813cb
diff --git a/crates/screenpipe-audio/src/utils/ffmpeg.rs b/crates/screenpipe-audio/src/utils/ffmpeg.rs
index c94fa2423..0063cdd5e 100644
--- a/crates/screenpipe-audio/src/utils/ffmpeg.rs
+++ b/crates/screenpipe-audio/src/utils/ffmpeg.rs
@@ -22,7 +22,7 @@ fn encode_single_audio(
) -> anyhow::Result<()> {
debug!("Starting FFmpeg process");
- let mut command = Command::new(find_ffmpeg_path().unwrap());
+ let mut command = screenpipe_core::ffmpeg_cmd(find_ffmpeg_path().unwrap());
command
.args([
"-f",
@@ -109,7 +109,7 @@ pub fn get_new_file_path_with_timestamp(
pub fn read_audio_from_file(path: &Path) -> Result<(Vec<f32>, u32)> {
let sample_rate: u32 = 16000;
- let mut command = Command::new(find_ffmpeg_path().unwrap());
+ let mut command = screenpipe_core::ffmpeg_cmd(find_ffmpeg_path().unwrap());
command
.args([
"-i",
diff --git a/crates/screenpipe-core/src/ffmpeg.rs b/crates/screenpipe-core/src/ffmpeg.rs
index 3bd08dc0f..507218223 100644
--- a/crates/screenpipe-core/src/ffmpeg.rs
+++ b/crates/screenpipe-core/src/ffmpeg.rs
@@ -21,6 +21,28 @@ pub fn find_ffmpeg_path() -> Option<PathBuf> {
FFMPEG_PATH.as_ref().map(|p| p.clone())
}
+/// Create a `std::process::Command` for ffmpeg with `CREATE_NO_WINDOW` on Windows.
+pub fn ffmpeg_cmd(path: impl AsRef<std::ffi::OsStr>) -> std::process::Command {
+ let mut cmd = std::process::Command::new(path);
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ cmd
+}
+
+/// Create a `tokio::process::Command` for ffmpeg with `CREATE_NO_WINDOW` on Windows.
+pub fn ffmpeg_cmd_async(path: impl AsRef<std::ffi::OsStr>) -> tokio::process::Command {
+ let mut cmd = tokio::process::Command::new(path);
+ #[cfg(windows)]
+ {
+ use std::os::windows::process::CommandExt;
+ cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
+ }
+ cmd
+}
+
fn find_ffmpeg_path_internal() -> Option<PathBuf> {
debug!("Starting search for ffmpeg executable");
diff --git a/crates/screenpipe-core/src/lib.rs b/crates/screenpipe-core/src/lib.rs
index 61bfc2604..cda062649 100644
--- a/crates/screenpipe-core/src/lib.rs
+++ b/crates/screenpipe-core/src/lib.rs
@@ -7,7 +7,7 @@ pub mod offline;
pub mod paths;
pub mod permissions;
pub mod pipes;
-pub use ffmpeg::find_ffmpeg_path;
+pub use ffmpeg::{find_ffmpeg_path, ffmpeg_cmd, ffmpeg_cmd_async};
mod language;
#[cfg(feature = "security")]
diff --git a/crates/screenpipe-engine/src/snapshot_compaction.rs b/crates/screenpipe-engine/src/snapshot_compaction.rs
index 605945b71..e27823e59 100644
--- a/crates/screenpipe-engine/src/snapshot_compaction.rs
+++ b/crates/screenpipe-engine/src/snapshot_compaction.rs
@@ -396,7 +396,7 @@ async fn start_ffmpeg_lowpri(
cmd
};
#[cfg(not(unix))]
- let mut command = tokio::process::Command::new(ffmpeg_path);
+ let mut command = screenpipe_core::ffmpeg_cmd_async(ffmpeg_path);
command
.args([
diff --git a/crates/screenpipe-engine/src/video.rs b/crates/screenpipe-engine/src/video.rs
index 8fcac9ad7..bbfe285b4 100644
--- a/crates/screenpipe-engine/src/video.rs
+++ b/crates/screenpipe-engine/src/video.rs
@@ -68,7 +68,7 @@ pub async fn start_ffmpeg_process(
info!("Starting FFmpeg process for file: {}", output_file);
let fps_str = fps.to_string();
- let mut command = tokio::process::Command::new(find_ffmpeg_path().unwrap());
+ let mut command = screenpipe_core::ffmpeg_cmd_async(find_ffmpeg_path().unwrap());
let mut args = vec![
"-f",
"image2pipe",
diff --git a/crates/screenpipe-engine/src/video_cache.rs b/crates/screenpipe-engine/src/video_cache.rs
index de341f5da..6ed513c5e 100644
--- a/crates/screenpipe-engine/src/video_cache.rs
+++ b/crates/screenpipe-engine/src/video_cache.rs
@@ -728,7 +728,7 @@ async fn extract_frame(
// Join frame numbers with commas and wrap in select filter
let select_filter = format!("select='eq(n,{})'", frame_positions.join(")+eq(n,"));
- let mut cmd = Command::new(&ffmpeg);
+ let mut cmd = screenpipe_core::ffmpeg_cmd_async(&ffmpeg);
cmd.args([
"-i",
&video_file_path,
diff --git a/crates/screenpipe-engine/src/video_utils.rs b/crates/screenpipe-engine/src/video_utils.rs
index fefa7a1e8..a56348cce 100644
--- a/crates/screenpipe-engine/src/video_utils.rs
+++ b/crates/screenpipe-engine/src/video_utils.rs
@@ -6,7 +6,7 @@ use image::codecs::jpeg::JpegEncoder;
use image::{DynamicImage, GenericImageView, Rgba};
use imageproc::filter::gaussian_blur_f32;
use oasgen::OaSchema;
-use screenpipe_core::find_ffmpeg_path;
+use screenpipe_core::{find_ffmpeg_path, ffmpeg_cmd_async};
use screenpipe_core::pii_removal::PiiRegion;
use screenpipe_db::VideoMetadata as DBVideoMetadata;
use serde::{Deserialize, Serialize};
@@ -85,7 +85,7 @@ pub async fn extract_frame(file_path: &str, offset_index: i64) -> Result<String>
file_path, offset_str
);
- let mut command = Command::new(ffmpeg_path);
+ let mut command = ffmpeg_cmd_async(ffmpeg_path);
command
.args([
"-ss",
@@ -160,7 +160,7 @@ pub async fn validate_media(file_path: &str) -> Result<()> {
}
let ffmpeg_path = find_ffmpeg_path().expect("failed to find ffmpeg path");
- let mut cmd = Command::new(ffmpeg_path);
+ let mut cmd = ffmpeg_cmd_async(ffmpeg_path);
cmd.args(["-v", "error", "-i", file_path, "-f", "null", "-"]);
#[cfg(windows)]
@@ -214,7 +214,7 @@ pub async fn merge_videos(
}
let ffmpeg_path = find_ffmpeg_path().expect("failed to find ffmpeg path");
- let mut cmd = Command::new(ffmpeg_path);
+ let mut cmd = ffmpeg_cmd_async(ffmpeg_path);
cmd.args([
"-f",
"concat",
@@ -305,7 +305,7 @@ pub async fn extract_frames_from_video(
let fps_filter = format!("fps={}", target_fps);
// Extract frames using ffmpeg
- let mut cmd = Command::new(&ffmpeg_path);
+ let mut cmd = ffmpeg_cmd_async(&ffmpeg_path);
cmd.args([
"-i",
video_path.to_str().unwrap(),
@@ -428,7 +428,7 @@ async fn get_video_fps_and_duration_uncached(
) -> Result<(f64, f64)> {
let ffprobe_path = get_ffprobe_path(ffmpeg_path);
- let mut cmd = Command::new(&ffprobe_path);
+ let mut cmd = ffmpeg_cmd_async(&ffprobe_path);
cmd.args([
"-v",
"quiet",
@@ -514,7 +514,7 @@ pub async fn get_video_metadata(video_path: &str) -> Result<VideoMetadata> {
let ffprobe_path = get_ffprobe_path(&ffmpeg_path);
// Try ffprobe first
- let mut cmd = Command::new(&ffprobe_path);
+ let mut cmd = ffmpeg_cmd_async(&ffprobe_path);
cmd.args([
"-v",
"quiet",
@@ -588,7 +588,7 @@ pub async fn get_video_metadata(video_path: &str) -> Result<VideoMetadata> {
// Helper function to get fps and duration
async fn get_video_technical_metadata(ffprobe_path: &Path, video_path: &str) -> Result<(f64, f64)> {
- let mut cmd = Command::new(ffprobe_path);
+ let mut cmd = ffmpeg_cmd_async(ffprobe_path);
cmd.args([
"-v",
"quiet",
@@ -787,7 +787,7 @@ pub async fn extract_frame_from_video(
output_path.display()
);
- let mut command = Command::new(ffmpeg_path);
+ let mut command = ffmpeg_cmd_async(ffmpeg_path);
command
.args([
"-ss",
@@ -890,7 +890,7 @@ pub async fn extract_high_quality_frame(
);
let output_path = output_dir.join(frame_filename);
- let mut command = Command::new(&ffmpeg_path);
+ let mut command = ffmpeg_cmd_async(&ffmpeg_path);
command.args([
"-y",
"-loglevel",