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: resolve ffprobe not found causing false VIDEO_CORRUPTED errors on compacted MP4s

Louis Beaumont1979a50b054d
diff --git a/crates/screenpipe-engine/src/routes/frames.rs b/crates/screenpipe-engine/src/routes/frames.rs
index 319f5514a..ff21db76f 100644
--- a/crates/screenpipe-engine/src/routes/frames.rs
+++ b/crates/screenpipe-engine/src/routes/frames.rs
@@ -176,7 +176,19 @@ pub async fn get_frame_data(
// No fallback found either
let err_str = e.to_string();
- if err_str.contains("VIDEO_CORRUPTED")
+ if err_str.contains("FFPROBE_NOT_FOUND") {
+ error!("ffprobe not found — frame extraction will fail for all compacted frames: {}", err_str);
+ Err((
+ StatusCode::INTERNAL_SERVER_ERROR,
+ JsonResponse(json!({
+ "error": "ffprobe not found - install ffprobe alongside ffmpeg to extract frames from compacted videos",
+ "error_type": "ffprobe_not_found",
+ "frame_id": frame_id,
+ "file_path": file_path,
+ "details": err_str
+ })),
+ ))
+ } else if err_str.contains("VIDEO_CORRUPTED")
|| err_str.contains("VIDEO_NOT_FOUND")
{
Err((
diff --git a/crates/screenpipe-engine/src/video_utils.rs b/crates/screenpipe-engine/src/video_utils.rs
index 0c4c2b61f..8e1abf17e 100644
--- a/crates/screenpipe-engine/src/video_utils.rs
+++ b/crates/screenpipe-engine/src/video_utils.rs
@@ -17,7 +17,7 @@ use std::path::PathBuf;
use std::sync::LazyLock;
use tokio::io::AsyncReadExt;
use tokio::sync::RwLock;
-use tracing::{debug, error, info};
+use tracing::{debug, error, info, warn};
use uuid::Uuid;
/// Global cache for video metadata (FPS, duration) to avoid repeated ffprobe calls.
@@ -27,28 +27,51 @@ use uuid::Uuid;
static VIDEO_METADATA_CACHE: LazyLock<RwLock<HashMap<String, (f64, f64)>>> =
LazyLock::new(|| RwLock::new(HashMap::with_capacity(100)));
-/// Get ffprobe path from ffmpeg path, handling Windows .exe extension
-/// Tries with .exe first on Windows, falls back to without
+/// Get ffprobe path from ffmpeg path, handling Windows .exe extension.
+/// Falls back to searching PATH via `which` if ffprobe isn't alongside ffmpeg.
fn get_ffprobe_path(ffmpeg_path: &Path) -> PathBuf {
#[cfg(windows)]
- {
- // Try with .exe first (standard Windows executable)
- let with_exe = ffmpeg_path.with_file_name("ffprobe.exe");
- if with_exe.exists() {
- return with_exe;
+ let candidates = [
+ ffmpeg_path.with_file_name("ffprobe.exe"),
+ ffmpeg_path.with_file_name("ffprobe"),
+ ];
+ #[cfg(not(windows))]
+ let candidates = [ffmpeg_path.with_file_name("ffprobe")];
+
+ for candidate in &candidates {
+ if candidate.exists() {
+ return candidate.clone();
}
- // Fall back to without .exe (some Windows configs find it anyway)
- let without_exe = ffmpeg_path.with_file_name("ffprobe");
- if without_exe.exists() {
- return without_exe;
+ }
+
+ // ffprobe not alongside ffmpeg — try PATH
+ #[cfg(unix)]
+ if let Ok(output) = std::process::Command::new("which").arg("ffprobe").output() {
+ if output.status.success() {
+ let path_str = String::from_utf8_lossy(&output.stdout).trim().to_string();
+ if !path_str.is_empty() {
+ return PathBuf::from(path_str);
+ }
}
- // Default to .exe version even if not found (let the error happen later)
- with_exe
}
- #[cfg(not(windows))]
- {
- ffmpeg_path.with_file_name("ffprobe")
+ #[cfg(windows)]
+ if let Ok(output) = std::process::Command::new("where").arg("ffprobe").output() {
+ if output.status.success() {
+ let path_str = String::from_utf8_lossy(&output.stdout).trim().to_string();
+ if let Some(first_line) = path_str.lines().next() {
+ if !first_line.is_empty() {
+ return PathBuf::from(first_line);
+ }
+ }
+ }
}
+
+ warn!(
+ "ffprobe not found alongside ffmpeg ({}) or in PATH — frame extraction from MP4 will fail",
+ ffmpeg_path.display()
+ );
+ // Return the default path so callers get a clear "not found" error
+ candidates[0].clone()
}
#[derive(Debug, Deserialize)]
@@ -730,16 +753,24 @@ pub async fn extract_frame_from_video(
Err(e) => {
// Check if this is a corrupted video (moov atom missing, invalid data, etc)
let err_str = e.to_string().to_lowercase();
- if err_str.contains("moov")
- || err_str.contains("invalid data")
- || err_str.contains("no such file")
- {
+ if err_str.contains("moov") || err_str.contains("invalid data") {
return Err(anyhow::anyhow!(
"VIDEO_CORRUPTED: cannot read metadata from {} - {}",
file_path,
e
));
}
+ // "no such file" from cmd.output() means ffprobe binary not found,
+ // not the video file (we already checked that above). Don't misreport
+ // as VIDEO_CORRUPTED — surface the real cause so it can be fixed.
+ if err_str.contains("no such file") || err_str.contains("os error 2") {
+ return Err(anyhow::anyhow!(
+ "FFPROBE_NOT_FOUND: cannot extract frame from {} - ffprobe binary not found. \
+ Ensure ffprobe is installed alongside ffmpeg. Error: {}",
+ file_path,
+ e
+ ));
+ }
error!("failed to get video metadata, using defaults: {}", e);
(1.0, f64::MAX) // Use MAX duration to disable validation on error
}