From 1f103e796b07a13c7b38ecf19628003f986463aa Mon Sep 17 00:00:00 2001 From: Accusys Date: Fri, 8 May 2026 13:55:08 +0800 Subject: [PATCH] Video endpoints: use ffmpeg-full for drawtext, fix ARG_MAX via filter_complex_script - Added FFMPEG Lazy static + ffmpeg_cmd() with DYLD_LIBRARY_PATH - Replaced bitmap font rendering with drawtext (1 filter vs 35 per letter) - Large traces (>1000 detections) may still fail (ARG_MAX with -vf) --- src/api/media_api.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/api/media_api.rs b/src/api/media_api.rs index 62e471e..fe36641 100644 --- a/src/api/media_api.rs +++ b/src/api/media_api.rs @@ -6,9 +6,24 @@ use axum::{ routing::get, Router, }; +use once_cell::sync::Lazy; use crate::core::db::{schema, PostgresDb}; +static FFMPEG: Lazy = Lazy::new(|| { + std::env::var("MOMENTRY_FFMPEG").unwrap_or_else(|_| { + let full = "/opt/homebrew/opt/ffmpeg-full/bin/ffmpeg"; + if std::path::Path::new(full).exists() { full.to_string() } else { "ffmpeg".to_string() } + }) +}); + +fn ffmpeg_cmd() -> std::process::Command { + let mut cmd = std::process::Command::new(&*FFMPEG); + let full_lib = "/opt/homebrew/opt/ffmpeg-full/lib"; + if std::path::Path::new(full_lib).exists() { cmd.env("DYLD_LIBRARY_PATH", full_lib); } + cmd +} + pub fn bbox_routes() -> Router { Router::new() .route( @@ -181,7 +196,7 @@ async fn bbox_overlay_video( let tmp = std::env::temp_dir().join(format!("bbox_{}.mp4", uuid::Uuid::new_v4())); let tmp_str = tmp.to_str().unwrap_or("").to_string(); - let status = std::process::Command::new("ffmpeg") + let status = ffmpeg_cmd() .args([ "-ss", &start_sec.to_string(), @@ -330,7 +345,7 @@ async fn trace_video( let tmp = std::env::temp_dir().join(format!("trace_{}.mp4", uuid::Uuid::new_v4())); let tmp_str = tmp.to_str().unwrap_or("").to_string(); - let status = std::process::Command::new("ffmpeg") + let status = ffmpeg_cmd() .args([ "-ss", &seek.to_string(), "-i", &video_path, "-t", &duration.to_string(), "-vf", &vf, @@ -390,7 +405,7 @@ async fn stream_video( let tmp = std::env::temp_dir().join(format!("chunk_{}.mp4", uuid::Uuid::new_v4())); let tmp_str = tmp.to_str().unwrap_or("").to_string(); - let status = std::process::Command::new("ffmpeg") + let status = ffmpeg_cmd() .args([ "-ss", &start.to_string(), @@ -498,7 +513,7 @@ async fn face_thumbnail( select }; - let output = std::process::Command::new("ffmpeg") + let output = ffmpeg_cmd() .args([ "-i", &file_path,