From 36e5372944b37b079d6bf124d549c8d13577736b Mon Sep 17 00:00:00 2001 From: BlueJayLouche Date: Fri, 25 Sep 2026 20:19:54 +1000 Subject: [PATCH 1/2] feat(io): run a bundled ffmpeg/ffprobe when one ships beside the app Recording and HAP conversion shelled out to bare `ffmpeg`/`ffprobe`, so they only worked with FFmpeg installed on PATH. rustjay_io::ffmpeg_tool prefers a copy next to the running executable (what packaged apps ship) and falls back to PATH; all six call sites use it. Co-Authored-By: Claude Opus 5.5 --- crates/rustjay-io/src/hap_encode.rs | 7 +++--- crates/rustjay-io/src/lib.rs | 31 ++++++++++++++++++++++++ crates/rustjay-io/src/output/recorder.rs | 8 +++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/crates/rustjay-io/src/hap_encode.rs b/crates/rustjay-io/src/hap_encode.rs index e7a5b9c8..c9ca208b 100644 --- a/crates/rustjay-io/src/hap_encode.rs +++ b/crates/rustjay-io/src/hap_encode.rs @@ -27,7 +27,8 @@ pub fn pix_fmt_has_alpha(pix_fmt: &str) -> bool { /// Convert any video to HAP using ffmpeg for *decode* and hap-qt for *encode*. /// -/// Both `ffmpeg` and `ffprobe` must be on PATH; a missing one is the error. +/// Needs `ffmpeg` and `ffprobe`, beside the executable or on PATH (see +/// [`crate::ffmpeg_tool`]); a missing one is the error. /// /// ffmpeg decodes to raw RGBA via stdout; we feed that into `HapFrameEncoder` /// plus `QtHapWriter`. The codec comes from the source's pixel format, via @@ -44,7 +45,7 @@ pub fn ffmpeg_to_hap(src: &std::path::Path, dst: &std::path::Path) -> anyhow::Re // --- probe: width, height, fps, pixel format via ffprobe --------------- // key=value output, not positional CSV: ffprobe emits fields in its own // order, not the order they were requested, so positions are not stable. - let probe = Command::new("ffprobe") + let probe = Command::new(crate::ffmpeg_tool("ffprobe")) .args([ "-v", "error", "-select_streams", "v:0", @@ -81,7 +82,7 @@ pub fn ffmpeg_to_hap(src: &std::path::Path, dst: &std::path::Path) -> anyhow::Re ); // --- decode: ffmpeg → raw RGBA on stdout ------------------------------ - let mut child = Command::new("ffmpeg") + let mut child = Command::new(crate::ffmpeg_tool("ffmpeg")) .args([ "-y", "-i", src.to_str().unwrap_or_default(), "-f", "rawvideo", "-pix_fmt", "rgba", "-an", "-", diff --git a/crates/rustjay-io/src/lib.rs b/crates/rustjay-io/src/lib.rs index 6b3a7a5d..69f182f9 100644 --- a/crates/rustjay-io/src/lib.rs +++ b/crates/rustjay-io/src/lib.rs @@ -33,5 +33,36 @@ pub use input::{SyphonInputReceiver, SyphonDiscovery}; pub use input::{SpoutDiscovery, SpoutInputReceiver}; pub use output::recorder::{list_audio_devices, Recorder, RecorderCodec}; pub use output::OutputManager; + +/// An FFmpeg command-line tool (`"ffmpeg"`, `"ffprobe"`) to run: the copy +/// shipped next to the running executable when there is one, so a packaged app +/// records and converts with nothing installed; otherwise the bare name, found +/// on `PATH`. +pub fn ffmpeg_tool(name: &str) -> std::path::PathBuf { + let exe = std::env::current_exe().ok(); + tool_beside(exe.as_deref().and_then(std::path::Path::parent), name) +} + +fn tool_beside(dir: Option<&std::path::Path>, name: &str) -> std::path::PathBuf { + let file = format!("{name}{}", std::env::consts::EXE_SUFFIX); + dir.map(|d| d.join(&file)) + .filter(|p| p.is_file()) + .unwrap_or_else(|| file.into()) +} + +#[cfg(test)] +mod ffmpeg_tool_tests { + #[test] + fn a_bundled_copy_wins_over_path() { + let dir = std::env::temp_dir().join(format!("rustjay-ffmpeg-tool-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let file = format!("ffmpeg{}", std::env::consts::EXE_SUFFIX); + // Nothing beside the executable: fall back to the bare name on PATH. + assert_eq!(super::tool_beside(Some(&dir), "ffmpeg"), std::path::PathBuf::from(&file)); + std::fs::write(dir.join(&file), b"").unwrap(); + assert_eq!(super::tool_beside(Some(&dir), "ffmpeg"), dir.join(&file)); + std::fs::remove_dir_all(&dir).ok(); + } +} #[cfg(target_os = "linux")] pub use v4l2_devices::{V4l2DeviceInfo, list_output_devices}; diff --git a/crates/rustjay-io/src/output/recorder.rs b/crates/rustjay-io/src/output/recorder.rs index 4411227e..4495b9fb 100644 --- a/crates/rustjay-io/src/output/recorder.rs +++ b/crates/rustjay-io/src/output/recorder.rs @@ -149,7 +149,7 @@ impl Recorder { path }; - let mut cmd = Command::new("ffmpeg"); + let mut cmd = Command::new(crate::ffmpeg_tool("ffmpeg")); cmd.arg("-y") // overwrite .arg("-hide_banner") .arg("-loglevel") @@ -357,7 +357,7 @@ impl Recorder { /// Length of a media file in seconds, or 0 if ffprobe can't say. fn duration(path: &Path) -> f64 { - Command::new("ffprobe") + Command::new(crate::ffmpeg_tool("ffprobe")) .args(["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0"]) .arg(path) .output() @@ -380,7 +380,7 @@ fn mux(video: &Path, audio: &Path, out: &Path) -> anyhow::Result<()> { // Capture opens before the first frame arrives, so the audio runs long at // the head — both were stopped together, so the excess is exactly the lead. let lead = duration(audio) - duration(video); - let mut cmd = Command::new("ffmpeg"); + let mut cmd = Command::new(crate::ffmpeg_tool("ffmpeg")); cmd.args(["-y", "-hide_banner", "-loglevel", "error"]); if lead > 0.02 { log::info!("[Recorder] trimming {:.2}s of audio lead-in", lead); @@ -465,7 +465,7 @@ impl AudioCapture { (config.sample_rate(), config.channels(), config.sample_format()); let path = sidecar(near, "audio", "m4a"); - let mut child = Command::new("ffmpeg") + let mut child = Command::new(crate::ffmpeg_tool("ffmpeg")) .args(["-y", "-hide_banner", "-loglevel", "error", "-f", "f32le", "-ar"]) .arg(rate.to_string()) .arg("-ac") From eb721af672be6d72806e2e76f83b0000f05a5b5b Mon Sep 17 00:00:00 2001 From: BlueJayLouche Date: Fri, 25 Sep 2026 20:51:56 +1000 Subject: [PATCH 2/2] fix(io): test module last (clippy items_after_test_module on Linux) Co-Authored-By: Claude Opus 5.5 --- crates/rustjay-io/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/rustjay-io/src/lib.rs b/crates/rustjay-io/src/lib.rs index 69f182f9..c3668cc8 100644 --- a/crates/rustjay-io/src/lib.rs +++ b/crates/rustjay-io/src/lib.rs @@ -50,6 +50,9 @@ fn tool_beside(dir: Option<&std::path::Path>, name: &str) -> std::path::PathBuf .unwrap_or_else(|| file.into()) } +#[cfg(target_os = "linux")] +pub use v4l2_devices::{V4l2DeviceInfo, list_output_devices}; + #[cfg(test)] mod ffmpeg_tool_tests { #[test] @@ -64,5 +67,3 @@ mod ffmpeg_tool_tests { std::fs::remove_dir_all(&dir).ok(); } } -#[cfg(target_os = "linux")] -pub use v4l2_devices::{V4l2DeviceInfo, list_output_devices};