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: new db data fields, snake_case warnings, ci cli, ci app, switch from mp3 to mp4 for audio encoding (same compute/storage effect, less dependency hell), fix tests, fix all

Louis Beaumontdcd5773eb74c
diff --git a/.github/workflows/release-cli.yml b/.github/workflows/release-cli.yml
index e6a81904d..2190b2765 100644
--- a/.github/workflows/release-cli.yml
+++ b/.github/workflows/release-cli.yml
@@ -37,14 +37,12 @@ jobs:
- name: Set up pkg-config for cross-compilation
run: |
if [ "${{ matrix.target }}" = "aarch64-apple-darwin" ]; then
- export PKG_CONFIG_SYSROOT_DIR=/opt/homebrew
- export PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig
+ echo "PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig" >> $GITHUB_ENV
+ echo "PKG_CONFIG_LIBDIR=/opt/homebrew/lib/pkgconfig" >> $GITHUB_ENV
else
- export PKG_CONFIG_SYSROOT_DIR=/usr/local
- export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
+ echo "PKG_CONFIG_PATH=/usr/local/lib/pkgconfig" >> $GITHUB_ENV
+ echo "PKG_CONFIG_LIBDIR=/usr/local/lib/pkgconfig" >> $GITHUB_ENV
fi
- echo "PKG_CONFIG_SYSROOT_DIR=$PKG_CONFIG_SYSROOT_DIR" >> $GITHUB_ENV
- echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV
- name: Build with Metal feature
run: |
@@ -148,34 +146,30 @@ jobs:
profile: minimal
override: true
- - name: Install FFmpeg
- run: |
- choco install ffmpeg
-
- - name: Install pkg-config
+ - name: Download FFmpeg
run: |
- choco install pkgconfiglite
+ $ProgressPreference = 'SilentlyContinue'
+ Invoke-WebRequest -Uri "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl-shared.zip" -OutFile "ffmpeg.zip"
+ Expand-Archive -Path "ffmpeg.zip" -DestinationPath "ffmpeg"
+ Move-Item -Path "ffmpeg\ffmpeg-master-latest-win64-gpl-shared" -Destination "C:\ffmpeg"
- - name: Set up pkg-config
+ - name: Set up environment
run: |
- echo "PKG_CONFIG_PATH=C:\ProgramData\chocolatey\lib\pkgconfiglite\tools\pkg-config\lib\pkgconfig" >> $GITHUB_ENV
- echo "C:\ProgramData\chocolatey\lib\pkgconfiglite\tools" >> $GITHUB_PATH
+ echo "C:\ffmpeg\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
+ echo "FFMPEG_DIR=C:\ffmpeg" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
+ echo "PKG_CONFIG_PATH=C:\ffmpeg\lib\pkgconfig" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Build release
run: |
cargo build --release --verbose
- - name: Download FFmpeg
- run: |
- $ProgressPreference = 'SilentlyContinue'
- Invoke-WebRequest -Uri "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip" -OutFile "ffmpeg.zip"
- Expand-Archive -Path "ffmpeg.zip" -DestinationPath "ffmpeg"
- Move-Item -Path "ffmpeg\ffmpeg-master-latest-win64-gpl\bin\*" -Destination "target\release\"
-
- name: Create deployment package
run: |
$VERSION = $env:GITHUB_REF -replace 'refs/tags/v', ''
- Compress-Archive -Path target\release\screenpipe.exe, target\release\ffmpeg.exe, target\release\ffprobe.exe -DestinationPath screenpipe-$VERSION-x86_64-pc-windows-msvc.zip
+ New-Item -ItemType Directory -Path "screenpipe-win64"
+ Copy-Item "target\release\screenpipe.exe" -Destination "screenpipe-win64"
+ Copy-Item "C:\ffmpeg\bin\*.dll" -Destination "screenpipe-win64"
+ Compress-Archive -Path "screenpipe-win64" -DestinationPath "screenpipe-$VERSION-x86_64-pc-windows-msvc.zip"
- name: Upload Artifact
uses: actions/upload-artifact@v2
diff --git a/README.md b/README.md
index a43a2427b..799ac239a 100644
--- a/README.md
+++ b/README.md
@@ -251,7 +251,7 @@ ffplay "data/2024-07-12_01-14-14.mp4"
Play a sample audio_recording from the database</summary>
```bash
-ffplay "data/Display 1 (output)_2024-07-12_01-14-11.mp3"
+ffplay "data/Display 1 (output)_2024-07-12_01-14-11.mp4"
```
</details>
diff --git a/examples/apps/screenpipe-app-tauri/scripts/pre_build.js b/examples/apps/screenpipe-app-tauri/scripts/pre_build.js
index 26c4cd152..f4c564025 100644
--- a/examples/apps/screenpipe-app-tauri/scripts/pre_build.js
+++ b/examples/apps/screenpipe-app-tauri/scripts/pre_build.js
@@ -53,7 +53,6 @@ const config = {
'libasound2-dev', // cpal
'libomp-dev', // OpenMP in ggml.ai
'libstdc++-12-dev', //ROCm
- 'libmp3lame-dev', // MP3 support
],
},
macos: {
@@ -78,7 +77,6 @@ if (platform == 'linux') {
if (hasFeature('opencl')) {
config.linux.aptPackages.push('libclblast-dev')
}
- config.linux.aptPackages.push('libmp3lame0') // Add MP3 support
for (const name of config.linux.aptPackages) {
await $`sudo apt-get install -y ${name}`
}
@@ -120,44 +118,14 @@ if (platform == 'windows') {
}
/* ########## macOS ########## */
-// if (platform == 'macos') {
-// // Install lame using Homebrew
-// await $`brew install lame`
-
-// // Setup FFMPEG
-// if (!(await fs.exists(config.ffmpegRealname))) {
-// await $`wget -nc --show-progress ${config.macos.ffmpegUrl} -O ${config.macos.ffmpegName}.tar.xz`
-// await $`tar xf ${config.macos.ffmpegName}.tar.xz`
-// await $`mv ${config.macos.ffmpegName} ${config.ffmpegRealname}`
-// await $`rm ${config.macos.ffmpegName}.tar.xz`
-// }
-
-// // Copy lame to ffmpeg ! NEED SUDO
-// await $`sudo cp -r /opt/homebrew/opt/lame/lib/* ${config.ffmpegRealname}/lib/`
-
-// // Set the DYLD_LIBRARY_PATH to include the FFmpeg lib directory
-// await fs.appendFile(process.env.DYLD_LIBRARY_PATH, path.join(cwd, config.ffmpegRealname, 'lib'))
-// }
if (platform == 'macos') {
- // Install FFmpeg and lame using Homebrew
- await $`brew install ffmpeg lame`
-
- // Set FFmpeg path to Homebrew's installation
- config.ffmpegRealname = '/opt/homebrew/opt/ffmpeg'
-
- // Create a symlink if it doesn't exist
- if (!(await fs.exists(path.join(cwd, 'ffmpeg')))) {
- await $`ln -s ${config.ffmpegRealname} ${path.join(cwd, 'ffmpeg')}`
+ // Setup FFMPEG
+ if (!(await fs.exists(config.ffmpegRealname))) {
+ await $`wget -nc --show-progress ${config.macos.ffmpegUrl} -O ${config.macos.ffmpegName}.tar.xz`
+ await $`tar xf ${config.macos.ffmpegName}.tar.xz`
+ await $`mv ${config.macos.ffmpegName} ${config.ffmpegRealname}`
+ await $`rm ${config.macos.ffmpegName}.tar.xz`
}
-
- // Update the exports object
- exports.ffmpeg = path.join(cwd, 'ffmpeg')
-
- // Ensure DYLD_LIBRARY_PATH includes FFmpeg lib directory
- const ffmpegLibPath = path.join(config.ffmpegRealname, 'lib')
- process.env.DYLD_LIBRARY_PATH = `${process.env.DYLD_LIBRARY_PATH || ''}:${ffmpegLibPath}`
-
- console.log(`FFmpeg installed and linked. Path: ${exports.ffmpeg}`)
}
// Nvidia
diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/tauri.linux.conf.json b/examples/apps/screenpipe-app-tauri/src-tauri/tauri.linux.conf.json
index 5b7955656..e4062ec54 100644
--- a/examples/apps/screenpipe-app-tauri/src-tauri/tauri.linux.conf.json
+++ b/examples/apps/screenpipe-app-tauri/src-tauri/tauri.linux.conf.json
@@ -4,8 +4,7 @@
"deb": {
"depends": [
"ffmpeg",
- "libopenblas-dev",
- "libmp3lame0"
+ "libopenblas-dev"
]
}
}
diff --git a/examples/apps/screenpipe-app-tauri/src-tauri/tauri.macos.conf.json b/examples/apps/screenpipe-app-tauri/src-tauri/tauri.macos.conf.json
index e8c77ffd9..13282e008 100644
--- a/examples/apps/screenpipe-app-tauri/src-tauri/tauri.macos.conf.json
+++ b/examples/apps/screenpipe-app-tauri/src-tauri/tauri.macos.conf.json
@@ -9,8 +9,7 @@
"ffmpeg/lib/libavutil.59.dylib",
"ffmpeg/lib/libffmpeg.7.dylib",
"ffmpeg/lib/libswresample.5.dylib",
- "ffmpeg/lib/libswscale.8.dylib",
- "ffmpeg/lib/libmp3lame.0.dylib"
+ "ffmpeg/lib/libswscale.8.dylib"
],
"entitlements": "entitlements.plist",
"signingIdentity": "-",
diff --git a/examples/ts/vercel-ai-chatbot/lib/chat/actions.tsx b/examples/ts/vercel-ai-chatbot/lib/chat/actions.tsx
index ce1bcce7c..2b4ce7f39 100644
--- a/examples/ts/vercel-ai-chatbot/lib/chat/actions.tsx
+++ b/examples/ts/vercel-ai-chatbot/lib/chat/actions.tsx
@@ -107,6 +107,7 @@ async function submitUserMessage(content: string) {
- Use the date & time args smartly to get the most relevant results. Current user date & time is ${new Date().toISOString()}
- Generate 3-5 queries to get the most relevant results. Use a single keyword that would match the user intent per query
- Use only one word per query (in the q field)
+ - Make sure to answer the user question, ignore the data in your prompt not relevant to the user question
`,
parameters: z.object({
queries: z
@@ -187,7 +188,7 @@ async function submitUserMessage(content: string) {
const dataForGPT = JSON.stringify(results, null, 2)
// Create a prompt for GPT-4
- const prompt = `Based on the following search results, please provide a concise and informative answer to the user's query "${content}":
+ const prompt = `Based on the following search results, please provide a concise and informative answer to the user's question "${content}":
${dataForGPT}
diff --git a/screenpipe-audio/Cargo.toml b/screenpipe-audio/Cargo.toml
index b86d5c6d1..4dfdf4342 100644
--- a/screenpipe-audio/Cargo.toml
+++ b/screenpipe-audio/Cargo.toml
@@ -39,7 +39,8 @@ base64 = "0.21.7"
anyhow = "1.0.86"
byteorder = "1.5.0"
hf-hub = "0.3.2"
-symphonia = { version = "0.5.4", features = ["mp3"] }
+# https://github.com/pdeljanov/Symphonia/tree/master?tab=readme-ov-file#optimizations
+symphonia = { version = "0.5.4", features = ["aac", "isomp4", "opt-simd"] }
rand = "0.8.5"
rubato = "0.15.0"
diff --git a/screenpipe-audio/benches/pcm_decode_benchmark.rs b/screenpipe-audio/benches/pcm_decode_benchmark.rs
index 33aba685a..edd593ded 100644
--- a/screenpipe-audio/benches/pcm_decode_benchmark.rs
+++ b/screenpipe-audio/benches/pcm_decode_benchmark.rs
@@ -7,7 +7,7 @@ fn benchmark_pcm_decode(c: &mut Criterion) {
// Assuming you have a sample audio file in your project for testing
let test_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("test_data")
- .join("selah.mp3");
+ .join("selah.mp4");
c.bench_function("pcm_decode", |b| {
b.iter(|| {
diff --git a/screenpipe-audio/benches/stt_benchmark.rs b/screenpipe-audio/benches/stt_benchmark.rs
index da3c85bb9..7d0149a82 100644
--- a/screenpipe-audio/benches/stt_benchmark.rs
+++ b/screenpipe-audio/benches/stt_benchmark.rs
@@ -7,7 +7,7 @@ use std::path::PathBuf;
fn benchmark_stt(c: &mut Criterion) {
let test_file_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("test_data")
- .join("selah.mp3");
+ .join("selah.mp4");
// Initialize WhisperModel outside the benchmark loop
let whisper_model = WhisperModel::new().expect("Failed to initialize WhisperModel");
diff --git a/screenpipe-audio/src/bin/screenpipe-audio.rs b/screenpipe-audio/src/bin/screenpipe-audio.rs
index 94e5aac36..157293580 100644
--- a/screenpipe-audio/src/bin/screenpipe-audio.rs
+++ b/screenpipe-audio/src/bin/screenpipe-audio.rs
@@ -68,12 +68,12 @@ async fn main() -> Result<()> {
return Err(anyhow!("No audio input devices found"));
}
- // delete .mp3 files (output*.mp3)
- std::fs::remove_file("output_0.mp3").unwrap_or_default();
- std::fs::remove_file("output_1.mp3").unwrap_or_default();
+ // delete .mp4 files (output*.mp4)
+ std::fs::remove_file("output_0.mp4").unwrap_or_default();
+ std::fs::remove_file("output_1.mp4").unwrap_or_default();
let chunk_duration = Duration::from_secs(5);
- let output_path = PathBuf::from("output.mp3");
+ let output_path = PathBuf::from("output.mp4");
let (whisper_sender, mut whisper_receiver) = create_whisper_channel().await?;
// Spawn threads for each device
let recording_threads: Vec<_> = devices
@@ -82,7 +82,7 @@ async fn main() -> Result<()> {
.map(|(i, device)| {
let device = Arc::new(device);
let whisper_sender = whisper_sender.clone();
- let output_path = output_path.with_file_name(format!("output_{}.mp3", i));
+ let output_path = output_path.with_file_name(format!("output_{}.mp4", i));
let device_control = Arc::new(AtomicBool::new(true));
let device_clone = Arc::clone(&device);
diff --git a/screenpipe-audio/src/core.rs b/screenpipe-audio/src/core.rs
index 6aeae0123..47452f04e 100644
--- a/screenpipe-audio/src/core.rs
+++ b/screenpipe-audio/src/core.rs
@@ -134,29 +134,31 @@ async fn run_ffmpeg(
"-i",
"pipe:0",
"-c:a",
- "libmp3lame",
+ "aac",
"-b:a",
"128k",
"-f",
- "mp3",
+ "mp4",
output_path.to_str().unwrap(),
])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped());
+ // ! tmp hack shouldnt be needed
// Explicitly set the library paths for the FFmpeg command
- if let Ok(ld_library_path) = std::env::var("LD_LIBRARY_PATH") {
- command.env("LD_LIBRARY_PATH", ld_library_path);
- }
- #[cfg(target_os = "macos")]
- if let Ok(dyld_library_path) = std::env::var("DYLD_LIBRARY_PATH") {
- command.env("DYLD_LIBRARY_PATH", dyld_library_path);
- }
+ // if let Ok(ld_library_path) = std::env::var("LD_LIBRARY_PATH") {
+ // command.env("LD_LIBRARY_PATH", ld_library_path);
+ // }
+ // #[cfg(target_os = "macos")]
+ // if let Ok(dyld_library_path) = std::env::var("DYLD_LIBRARY_PATH") {
+ // command.env("DYLD_LIBRARY_PATH", dyld_library_path);
+ // }
debug!("FFmpeg command: {:?}", command);
- let mut ffmpeg: tokio::process::Child = command.spawn().expect("Failed to spawn FFmpeg process");
+ let mut ffmpeg: tokio::process::Child =
+ command.spawn().expect("Failed to spawn FFmpeg process");
debug!("FFmpeg process spawned");
let mut stdin = ffmpeg.stdin.take().expect("Failed to open stdin");
let start_time = std::time::Instant::now();
diff --git a/screenpipe-audio/test_data/selah.mp4 b/screenpipe-audio/test_data/selah.mp4
new file mode 100644
index 000000000..a9f5b9593
Binary files /dev/null and b/screenpipe-audio/test_data/selah.mp4 differ
diff --git a/screenpipe-audio/tests/core_tests.rs b/screenpipe-audio/tests/core_tests.rs
index f24044783..5e50c80ee 100644
--- a/screenpipe-audio/tests/core_tests.rs
+++ b/screenpipe-audio/tests/core_tests.rs
@@ -48,7 +48,7 @@ mod tests {
let start = std::time::Instant::now();
let whisper_model = WhisperModel::new().unwrap();
- let text = stt("./test_data/selah.mp3", &whisper_model).unwrap();
+ let text = stt("./test_data/selah.mp4", &whisper_model).unwrap();
let duration = start.elapsed();
println!("Speech to text completed in {:?}", duration);
@@ -66,7 +66,7 @@ mod tests {
let device_spec = Arc::new(default_output_device().unwrap());
let duration = Duration::from_secs(30); // Record for 3 seconds
let time = Utc::now().timestamp_millis();
- let output_path = PathBuf::from(format!("test_output_{}.mp3", time));
+ let output_path = PathBuf::from(format!("test_output_{}.mp4", time));
let (sender, mut receiver) = unbounded_channel();
let is_running = Arc::new(AtomicBool::new(true));
@@ -122,7 +122,7 @@ mod tests {
let device_spec = Arc::new(default_output_device().unwrap());
let duration = Duration::from_secs(30);
let time = Utc::now().timestamp_millis();
- let output_path = PathBuf::from(format!("test_output_interrupt_{}.mp3", time));
+ let output_path = PathBuf::from(format!("test_output_interrupt_{}.mp4", time));
let (sender, mut receiver) = unbounded_channel();
let is_running = Arc::new(AtomicBool::new(true));
let is_running_clone = Arc::clone(&is_running);
@@ -221,7 +221,7 @@ mod tests {
// Setup
let device_spec = Arc::new(default_output_device().unwrap());
let output_path =
- PathBuf::from(format!("test_output_{}.mp3", Utc::now().timestamp_millis()));
+ PathBuf::from(format!("test_output_{}.mp4", Utc::now().timestamp_millis()));
let output_path_2 = output_path.clone();
let (whisper_sender, mut whisper_receiver) = create_whisper_channel().await.unwrap();
let is_running = Arc::new(AtomicBool::new(true));
diff --git a/screenpipe-core/src/ffmpeg.rs b/screenpipe-core/src/ffmpeg.rs
index 51089b136..300425c53 100644
--- a/screenpipe-core/src/ffmpeg.rs
+++ b/screenpipe-core/src/ffmpeg.rs
@@ -1,5 +1,5 @@
use log::{debug, error};
-use std::{collections::HashSet, path::PathBuf};
+use std::path::PathBuf;
use which::which;
#[cfg(windows)]
@@ -16,123 +16,72 @@ const CREATE_NO_WINDOW: u32 = 0x08000000;
pub fn find_ffmpeg_path() -> Option<PathBuf> {
debug!("Starting search for ffmpeg executable");
- let mut ffmpeg_path = None;
- // Check if `ffmpeg` is in the PATH environment variable using the `which` crate
+ // Check if `ffmpeg` is in the PATH environment variable
if let Ok(path) = which(EXECUTABLE_NAME) {
debug!("Found ffmpeg in PATH: {:?}", path);
- ffmpeg_path = Some(path);
- } else {
- debug!("ffmpeg not found in PATH");
+ return Some(path);
}
+ debug!("ffmpeg not found in PATH");
// Check in current working directory
- let cwd = std::env::current_dir().ok()?;
- debug!("Current working directory: {:?}", cwd);
- let ffmpeg_in_cwd = cwd.join(EXECUTABLE_NAME);
- if ffmpeg_in_cwd.is_file() && ffmpeg_in_cwd.exists() {
- debug!(
- "Found ffmpeg in current working directory: {:?}",
- ffmpeg_in_cwd
- );
- ffmpeg_path = Some(ffmpeg_in_cwd);
- } else {
+ if let Ok(cwd) = std::env::current_dir() {
+ debug!("Current working directory: {:?}", cwd);
+ let ffmpeg_in_cwd = cwd.join(EXECUTABLE_NAME);
+ if ffmpeg_in_cwd.is_file() && ffmpeg_in_cwd.exists() {
+ debug!(
+ "Found ffmpeg in current working directory: {:?}",
+ ffmpeg_in_cwd
+ );
+ return Some(ffmpeg_in_cwd);
+ }
debug!("ffmpeg not found in current working directory");
}
// Check in the same folder as the executable
if let Ok(exe_path) = std::env::current_exe() {
- let exe_folder = exe_path.parent()?;
- debug!("Executable folder: {:?}", exe_folder);
- let ffmpeg_in_exe_folder = exe_folder.join(EXECUTABLE_NAME);
- if ffmpeg_in_exe_folder.exists() {
- debug!(
- "Found ffmpeg in executable folder: {:?}",
- ffmpeg_in_exe_folder
- );
- ffmpeg_path = Some(ffmpeg_in_exe_folder);
- } else {
- debug!("ffmpeg not found in executable folder");
- }
- // For macOS, check in the Resources folder next to the executable
- #[cfg(target_os = "macos")]
- {
- let resources_folder = exe_folder.join("../Resources");
- debug!("Resources folder: {:?}", resources_folder);
- let ffmpeg_in_resources = resources_folder.join(EXECUTABLE_NAME);
- if ffmpeg_in_resources.exists() {
+ if let Some(exe_folder) = exe_path.parent() {
+ debug!("Executable folder: {:?}", exe_folder);
+ let ffmpeg_in_exe_folder = exe_folder.join(EXECUTABLE_NAME);
+ if ffmpeg_in_exe_folder.exists() {
debug!(
- "Found ffmpeg in Resources folder: {:?}",
- ffmpeg_in_resources
+ "Found ffmpeg in executable folder: {:?}",
+ ffmpeg_in_exe_folder
);
- ffmpeg_path = Some(ffmpeg_in_resources);
- } else {
+ return Some(ffmpeg_in_exe_folder);
+ }
+ debug!("ffmpeg not found in executable folder");
+
+ // Platform-specific checks
+ #[cfg(target_os = "macos")]
+ {
+ let resources_folder = exe_folder.join("../Resources");
+ debug!("Resources folder: {:?}", resources_folder);
+ let ffmpeg_in_resources = resources_folder.join(EXECUTABLE_NAME);
+ if ffmpeg_in_resources.exists() {
+ debug!(
+ "Found ffmpeg in Resources folder: {:?}",
+ ffmpeg_in_resources
+ );
+ return Some(ffmpeg_in_resources);
+ }
debug!("ffmpeg not found in Resources folder");
}
- }
- #[cfg(target_os = "linux")]
- {
- let lib_folder = exe_folder.join("lib");
- debug!("Lib folder: {:?}", lib_folder);
- let ffmpeg_in_lib = lib_folder.join(EXECUTABLE_NAME);
- if ffmpeg_in_lib.exists() {
- debug!("Found ffmpeg in lib folder: {:?}", ffmpeg_in_lib);
- ffmpeg_path = Some(ffmpeg_in_lib);
- } else {
+
+ #[cfg(target_os = "linux")]
+ {
+ let lib_folder = exe_folder.join("lib");
+ debug!("Lib folder: {:?}", lib_folder);
+ let ffmpeg_in_lib = lib_folder.join(EXECUTABLE_NAME);
+ if ffmpeg_in_lib.exists() {
+ debug!("Found ffmpeg in lib folder: {:?}", ffmpeg_in_lib);
+ return Some(ffmpeg_in_lib);
+ }
debug!("ffmpeg not found in lib folder");
}
}
}
- if let Some(path) = ffmpeg_path {
- return Some(path);
- }
-
-
- // if let Some(path) = ffmpeg_path {
- // let current_ld_path = std::env::var("LD_LIBRARY_PATH").unwrap_or_default();
- // let current_dyld_path = std::env::var("DYLD_LIBRARY_PATH").unwrap_or_default();
-
- // let mut new_paths = HashSet::new();
-
- // // Add Homebrew lib paths
- // #[cfg(target_os = "macos")]
- // {
- // new_paths.insert("/opt/homebrew/opt/ffmpeg/lib".to_string());
- // new_paths.insert("/opt/homebrew/opt/lame/lib".to_string());
- // new_paths.insert("/Applications/screenpipe.app/Contents/Frameworks".to_string());
- // }
-
- // // Function to update environment variable
- // fn update_env_var(name: &str, current: &str, new_paths: &HashSet<String>) {
- // let current_set: HashSet<_> = current.split(':').map(String::from).collect();
- // let combined: HashSet<_> = current_set.union(new_paths).cloned().collect();
- // let updated = combined.into_iter().collect::<Vec<_>>().join(":");
- // std::env::set_var(name, &updated);
- // debug!("Updated {}: {}", name, updated);
- // }
-
- // // Update LD_LIBRARY_PATH
- // update_env_var("LD_LIBRARY_PATH", &current_ld_path, &new_paths);
-
- // // Update DYLD_LIBRARY_PATH for macOS
- // #[cfg(target_os = "macos")]
- // update_env_var("DYLD_LIBRARY_PATH", &current_dyld_path, &new_paths);
-
- // // Print out the updated environment variables
- // debug!(
- // "Updated LD_LIBRARY_PATH: {:?}",
- // std::env::var("LD_LIBRARY_PATH")
- // );
- // #[cfg(target_os = "macos")]
- // debug!(
- // "Updated DYLD_LIBRARY_PATH: {:?}",
- // std::env::var("DYLD_LIBRARY_PATH")
- // );
-
- // return Some(path);
- // }
error!("ffmpeg not found");
- // crash
- panic!("ffmpeg not found");
+ None // Return None if ffmpeg is not found
}
diff --git a/screenpipe-server/Cargo.toml b/screenpipe-server/Cargo.toml
index a7d1bfe85..3cfaa20c4 100644
--- a/screenpipe-server/Cargo.toml
+++ b/screenpipe-server/Cargo.toml
@@ -78,6 +78,9 @@ tracing = { workspace = true }
tower = "0.4"
futures = "0.3.17"
+# Directory management
+dirs = "5.0"
+
[dev-dependencies]
tempfile = "3.3.0"
diff --git a/screenpipe-server/benches/db_benchmarks.rs b/screenpipe-server/benches/db_benchmarks.rs
index 8e54318aa..3a92c0183 100644
--- a/screenpipe-server/benches/db_benchmarks.rs
+++ b/screenpipe-server/benches/db_benchmarks.rs
@@ -15,10 +15,10 @@ async fn setup_large_db(size: usize) -> DatabaseManager {
let ocr_text = format!("OCR text {}", rng.gen::<u32>());
let text_json = format!(r#"{{"text": "{}"}}"#, ocr_text);
let new_text_json_vs_previous_frame = format!(r#"{{"text": "{}"}}"#, ocr_text);
- let raw_data_output_from_OCR = format!(r#"{{"output": "{}"}}"#, ocr_text);
- db.insert_ocr_text(frame_id, &ocr_text, &text_json, &new_text_json_vs_previous_frame, &raw_data_output_from_OCR).await.unwrap();
+ let raw_data_output_from_ocr = format!(r#"{{"output": "{}"}}"#, ocr_text);
+ db.insert_ocr_text(frame_id, &ocr_text, &text_json, &new_text_json_vs_previous_frame, &raw_data_output_from_ocr).await.unwrap();
- let audio_id = db.insert_audio_chunk("test_audio.mp3").await.unwrap();
+ let audio_id = db.insert_audio_chunk("test_audio.mp4").await.unwrap();
let audio_text = format!("Audio transcription {}", rng.gen::<u32>());
db.insert_audio_transcription(audio_id, &audio_text, 0)
.await
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index 5f78142a2..f71fcbe0d 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -3,6 +3,7 @@ use std::{
fs,
net::SocketAddr,
ops::Deref,
+ path::PathBuf,
sync::{atomic::AtomicBool, Arc},
time::Duration,
};
@@ -10,6 +11,7 @@ use std::{
use clap::Parser;
#[allow(unused_imports)]
use colored::Colorize;
+use dirs::home_dir;
use log::{debug, info, LevelFilter};
use screenpipe_audio::{
default_input_device, default_output_device, list_audio_devices, parse_audio_device,
@@ -78,8 +80,8 @@ struct Cli {
list_audio_devices: bool,
/// Data directory
- #[arg(long, default_value_t = String::from("./data"))] // TODO $HOME/.screenpipe
- data_dir: String,
+ #[arg(long)]
+ data_dir: Option<String>,
/// Enable debug logging for screenpipe modules
#[arg(long)]
@@ -90,6 +92,18 @@ struct Cli {
save_text_files: bool,
}
+fn get_base_dir(custom_path: Option<String>) -> anyhow::Result<PathBuf> {
+ let default_path = home_dir()
+ .ok_or_else(|| anyhow::anyhow!("Failed to get home directory"))?
+ .join(".screenpipe");
+
+ let base_dir = custom_path.map(PathBuf::from).unwrap_or(default_path);
+ let data_dir = base_dir.join("data");
+
+ fs::create_dir_all(&data_dir)?;
+ Ok(data_dir)
+}
+
#[tokio::main]
async fn main() -> anyhow::Result<()> {
if find_ffmpeg_path().is_none() {
@@ -112,7 +126,7 @@ async fn main() -> anyhow::Result<()> {
}
// Example usage of the new flag
if cli.save_text_files {
- println!("Text files will be saved.");
+ debug!("Text files will be saved.");
}
builder.init();
@@ -158,10 +172,6 @@ async fn main() -> anyhow::Result<()> {
is_running: false,
is_paused: false,
};
- // let _ = audio_devices_control_sender.send_deadline(
- // (device.clone(), device_control.clone()),
- // Instant::now() + Duration::from_secs(10),
- // );
devices_status.insert(device.clone(), device_control);
info!(" {}", device);
}
@@ -176,10 +186,6 @@ async fn main() -> anyhow::Result<()> {
is_running: true,
is_paused: false,
};
- // let _ = audio_devices_control_sender.send_deadline(
- // (input_device.clone(), device_control.clone()),
- // Instant::now() + Duration::from_secs(15),
- // );
devices_status.insert(input_device, device_control);
}
if let Ok(output_device) = default_output_device() {
@@ -188,10 +194,6 @@ async fn main() -> anyhow::Result<()> {
is_running: true,
is_paused: false,
};
- // let _ = audio_devices_control_sender.send_deadline(
- // (output_device.clone(), device_control.clone()),
- // Instant::now() + Duration::from_secs(15),
- // );
devices_status.insert(output_device, device_control);
}
} else {
@@ -203,10 +205,6 @@ async fn main() -> anyhow::Result<()> {
is_running: true,
is_paused: false,
};
- // let _ = audio_devices_control_sender.send_deadline(
- // (device.clone(), device_control.clone()),
- // Instant::now() + Duration::from_secs(15),
- // );
devices_status.insert(device, device_control);
}
}
@@ -240,9 +238,8 @@ async fn main() -> anyhow::Result<()> {
);
resource_monitor.start_monitoring(Duration::from_secs(10)); // Log every 10 seconds
- let local_data_dir = cli.data_dir; // TODO: Use $HOME/.screenpipe/data
- fs::create_dir_all(&local_data_dir)?;
- let local_data_dir = Arc::new(local_data_dir);
+ let local_data_dir = get_base_dir(cli.data_dir)?;
+ let local_data_dir = Arc::new(local_data_dir.to_string_lossy().into_owned());
let local_data_dir_record = local_data_dir.clone();
let db = Arc::new(
DatabaseManager::new(&format!("{}/db.sqlite", local_data_dir))
@@ -250,7 +247,7 @@ async fn main() -> anyhow::Result<()> {
.map_err(|e| {
eprintln!("Failed to initialize database: {:?}", e);
e
- })?
+ })?,
);
info!(
"Database initialized, will store files in {}",
@@ -278,7 +275,7 @@ async fn main() -> anyhow::Result<()> {
control_rx,
vision_control,
audio_devices_control_receiver,
- cli.save_text_files,
+ cli.save_text_files,
)
.await
}
@@ -306,13 +303,7 @@ async fn main() -> anyhow::Result<()> {
info!("Server started on http://localhost:{}", cli.port);
// print screenpipe in gradient
- println!(
- "\n\n{}",
- DISPLAY
- .truecolor(147, 112, 219)
- .on_truecolor(255, 255, 255)
- .bold()
- );
+ println!("\n\n{}", DISPLAY.truecolor(147, 112, 219).bold());
println!(
"\n{}",
"Build AI apps that have the full context"
@@ -328,4 +319,4 @@ async fn main() -> anyhow::Result<()> {
loop {
tokio::time::sleep(Duration::from_secs(1)).await;
}
-}
\ No newline at end of file
+}
diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rs
index 7e55c433c..0409fdfe8 100644
--- a/screenpipe-server/src/core.rs
+++ b/screenpipe-server/src/core.rs
@@ -141,9 +141,9 @@ async fn record_video(
Ok(frame_id) => {
let text_json = serde_json::to_string(&frame.text_json).unwrap_or_default();
let new_text_json_vs_previous_frame = serde_json::to_string(&frame.new_text_json).unwrap_or_default();
- let raw_data_output_from_OCR = DataOutputWrapper { data_output: frame.data_output }.to_json();
+ let raw_data_output_from_ocr = DataOutputWrapper { data_output: frame.data_output }.to_json();
- if let Err(e) = db.insert_ocr_text(frame_id, &frame.text, &text_json, &new_text_json_vs_previous_frame, &raw_data_output_from_OCR).await {
+ if let Err(e) = db.insert_ocr_text(frame_id, &frame.text, &text_json, &new_text_json_vs_previous_frame, &raw_data_output_from_ocr).await {
error!("Failed to insert OCR text: {}", e);
}
debug!("Inserted frame {} with OCR text", frame_id);
@@ -218,7 +218,7 @@ async fn record_audio(
let new_file_name = Utc::now().format("%Y-%m-%d_%H-%M-%S").to_string();
let file_path = format!(
- "{}/{}_{}.mp3",
+ "{}/{}_{}.mp4",
output_path_clone, audio_device_clone, new_file_name
);
info!(
diff --git a/screenpipe-server/src/db.rs b/screenpipe-server/src/db.rs
index 9cd405d1c..c32a6e30e 100644
--- a/screenpipe-server/src/db.rs
+++ b/screenpipe-server/src/db.rs
@@ -19,8 +19,8 @@ pub struct OCRResult {
pub frame_id: i64,
pub ocr_text: String,
pub text_json: String, // Store as JSON string
- pub new_text_json: String, // Store as JSON string
- pub data_output: String, // Store as JSON string
+ pub new_text_json_vs_previous_frame: String, // Store as JSON string
+ pub raw_data_output_from_ocr: String, // Store as JSON string
pub timestamp: DateTime<Utc>,
pub file_path: String,
pub offset_index: i64,
@@ -51,9 +51,6 @@ pub struct DatabaseManager {
impl DatabaseManager {
pub async fn new(database_path: &str) -> Result<Self, sqlx::Error> {
- // if std::env::var("RUST_LOG").is_err() {
- // env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
- // }
debug!("db.rs initialized successfully.");
let connection_string = format!("sqlite:{}", database_path);
@@ -173,7 +170,7 @@ impl DatabaseManager {
text: &str,
text_json: &str,
new_text_json_vs_previous_frame: &str,
- raw_data_output_from_OCR: &str,
+ raw_data_output_from_ocr: &str,
) -> Result<(), sqlx::Error> {
// Function to limit string length
fn limit_string(s: &str) -> String {
@@ -190,7 +187,7 @@ impl DatabaseManager {
limit_string(text),
limit_string(text_json),
limit_string(new_text_json_vs_previous_frame),
- limit_string(raw_data_output_from_OCR)
+ limit_string(raw_data_output_from_ocr)
);
let mut tx = self.pool.begin().await?;
@@ -199,7 +196,7 @@ impl DatabaseManager {
.bind(text)
.bind(text_json)
.bind(new_text_json_vs_previous_frame)
- .bind(raw_data_output_from_OCR)
+ .bind(raw_data_output_from_ocr)
.execute(&mut *tx)
.await?;
@@ -264,8 +261,8 @@ impl DatabaseManager {
ocr_text.frame_id,
ocr_text.text as ocr_text,
ocr_text.text_json,
- ocr_text.new_text_json,
- ocr_text.data_output,
+ ocr_text.new_text_json_vs_previous_frame,
+ ocr_text.raw_data_output_from_OCR,
frames.timestamp,
video_chunks.file_path,
frames.offset_index
@@ -364,8 +361,8 @@ impl DatabaseManager {
ocr_text.frame_id,
ocr_text.text as ocr_text,
ocr_text.text_json,
- ocr_text.new_text_json,
- ocr_text.data_output,
+ ocr_text.new_text_json_vs_previous_frame,
+ ocr_text.raw_data_output_from_OCR,
frames.timestamp,
video_chunks.file_path,
frames.offset_index
diff --git a/screenpipe-server/src/migrations/20240716120002_snake_case.sql b/screenpipe-server/src/migrations/20240716120002_snake_case.sql
new file mode 100644
index 000000000..6a130c810
--- /dev/null
+++ b/screenpipe-server/src/migrations/20240716120002_snake_case.sql
@@ -0,0 +1,3 @@
+ALTER TABLE ocr_text RENAME COLUMN raw_data_output_from_OCR TO raw_data_output_from_ocr;
+DROP INDEX IF EXISTS idx_ocr_text_raw_data_output_from_OCR;
+CREATE INDEX IF NOT EXISTS idx_ocr_text_raw_data_output_from_ocr ON ocr_text(raw_data_output_from_ocr);
diff --git a/screenpipe-server/src/video.rs b/screenpipe-server/src/video.rs
index 43ead99dc..6d147a5d1 100644
--- a/screenpipe-server/src/video.rs
+++ b/screenpipe-server/src/video.rs
@@ -57,15 +57,6 @@ impl VideoCapture {
let _queue_thread = tokio::spawn(async move {
while *capture_thread_is_running.lock().await {
if let Some(result) = result_receiver.recv().await {
- // debug!(
- // "Received result from capture thread: frame_number: {:?}",
- // result.frame_number
- // );
- // debug!(
- // "Received result from capture thread: timestamp: {:?}",
- // result.timestamp
- // );
- // debug!("Received result from capture thread: text: {:?}", result.text);
capture_frame_queue.lock().await.push_back(result);
}
}
diff --git a/screenpipe-server/tests/db.rs b/screenpipe-server/tests/db.rs
index e95153838..86dc7dabe 100644
--- a/screenpipe-server/tests/db.rs
+++ b/screenpipe-server/tests/db.rs
@@ -12,7 +12,7 @@ mod tests {
let db = setup_test_db().await;
let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();
let frame_id = db.insert_frame().await.unwrap();
- db.insert_ocr_text(frame_id, "Hello, world!").await.unwrap();
+ db.insert_ocr_text(frame_id, "Hello, world!", "", "", "").await.unwrap();
let results = db
.search("Hello", ContentType::OCR, 100, 0, None, None)
@@ -30,7 +30,7 @@ mod tests {
#[tokio::test]
async fn test_insert_and_search_audio() {
let db = setup_test_db().await;
- let audio_chunk_id = db.insert_audio_chunk("test_audio.mp3").await.unwrap();
+ let audio_chunk_id = db.insert_audio_chunk("test_audio.mp4").await.unwrap();
db.insert_audio_transcription(audio_chunk_id, "Hello from audio", 0)
.await
.unwrap();
@@ -42,7 +42,7 @@ mod tests {
assert_eq!(results.len(), 1);
if let SearchResult::Audio(audio_result) = &results[0] {
assert_eq!(audio_result.transcription, "Hello from audio");
- assert_eq!(audio_result.file_path, "test_audio.mp3");
+ assert_eq!(audio_result.file_path, "test_audio.mp4");
} else {
panic!("Expected Audio result");
}
@@ -55,12 +55,12 @@ mod tests {
// Insert OCR data
let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();
let frame_id = db.insert_frame().await.unwrap();
- db.insert_ocr_text(frame_id, "Hello from OCR")
+ db.insert_ocr_text(frame_id, "Hello from OCR", "", "", "")
.await
.unwrap();
// Insert Audio data
- let audio_chunk_id = db.insert_audio_chunk("test_audio.mp3").await.unwrap();
+ let audio_chunk_id = db.insert_audio_chunk("test_audio.mp4").await.unwrap();
db.insert_audio_transcription(audio_chunk_id, "Hello from audio", 0)
.await
.unwrap();
@@ -93,12 +93,12 @@ mod tests {
// Insert OCR data
let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();
let frame_id1 = db.insert_frame().await.unwrap();
- db.insert_ocr_text(frame_id1, "Hello from OCR 1")
+ db.insert_ocr_text(frame_id1, "Hello from OCR 1", "", "", "")
.await
.unwrap();
// Insert first audio data
- let audio_chunk_id = db.insert_audio_chunk("test_audio.mp3").await.unwrap();
+ let audio_chunk_id = db.insert_audio_chunk("test_audio.mp4").await.unwrap();
db.insert_audio_transcription(audio_chunk_id, "Hello from audio 1", 0)
.await
.unwrap();
@@ -113,7 +113,7 @@ mod tests {
// Insert remaining data
let frame_id2 = db.insert_frame().await.unwrap();
- db.insert_ocr_text(frame_id2, "Hello from OCR 2")
+ db.insert_ocr_text(frame_id2, "Hello from OCR 2", "", "", "")
.await
.unwrap();
@@ -195,12 +195,12 @@ mod tests {
// Insert OCR data
let _ = db.insert_video_chunk("test_video.mp4").await.unwrap();
let frame_id1 = db.insert_frame().await.unwrap();
- db.insert_ocr_text(frame_id1, "Hello from OCR 1")
+ db.insert_ocr_text(frame_id1, "Hello from OCR 1", "", "", "")
.await
.unwrap();
// Insert first audio data
- let audio_chunk_id = db.insert_audio_chunk("test_audio.mp3").await.unwrap();
+ let audio_chunk_id = db.insert_audio_chunk("test_audio.mp4").await.unwrap();
db.insert_audio_transcription(audio_chunk_id, "Hello from audio 1", 0)
.await
.unwrap();
@@ -213,7 +213,7 @@ mod tests {
// Insert remaining data
let frame_id2 = db.insert_frame().await.unwrap();
- db.insert_ocr_text(frame_id2, "Hello from OCR 2")
+ db.insert_ocr_text(frame_id2, "Hello from OCR 2", "", "", "")
.await
.unwrap();