Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: video rendering issue in windows #372

Merged
merged 7 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 40 additions & 37 deletions screenpipe-app-tauri/scripts/pre_build.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,6 @@ const config = {
},
}

async function findWget() {
const possiblePaths = [
'C:\\ProgramData\\chocolatey\\bin\\wget.exe',
'C:\\Program Files\\Git\\mingw64\\bin\\wget.exe',
'C:\\msys64\\usr\\bin\\wget.exe',
'C:\\Windows\\System32\\wget.exe',
'wget' // This will work if wget is in PATH
];

for (const wgetPath of possiblePaths) {
try {
await $`${wgetPath} --version`.quiet();
console.log(`wget found at: ${wgetPath}`);
return wgetPath;
} catch (error) {
// wget not found at this path, continue searching
}
}

console.error('wget not found. Please install wget and make sure it\'s in your PATH.');
process.exit(1);
}

// Export for Github actions
const exports = {
ffmpeg: path.join(cwd, config.ffmpegRealname),
Expand Down Expand Up @@ -140,7 +117,26 @@ if (platform == 'linux') {

/* ########## Windows ########## */
if (platform == 'windows') {
const wgetPath = await findWget();

const childProcess = require('child_process');
async function exePath(command) {
try {
const result = childProcess.execSync(`where.exe ${command}`, { encoding: "utf-8" });
let output = result.trim()
if (output.length > 0 && !output.startsWith('INFO: Could not find')) {
const lines = output.split('\n');
const executablePath = lines[0].replace(/^\s+|\s+$/gm, '').trim();
return executablePath;
} else {
throw new Error('Command not found');
}
} catch (error) {
console.log(`${command} not found, Please install it`)
return null;
}
}

const wgetPath = await exePath("wget");

console.log('Copying screenpipe binary...');

Expand Down Expand Up @@ -171,11 +167,12 @@ if (platform == 'windows') {
// process.exit(1);
}

const sevenZipPath = await exePath("7z");

// Setup FFMPEG
if (!(await fs.exists(config.ffmpegRealname))) {
await $`${wgetPath} -nc --no-check-certificate --show-progress ${config.windows.ffmpegUrl} -O ${config.windows.ffmpegName}.7z`
await $`'C:\\Program Files\\7-Zip\\7z.exe' x ${config.windows.ffmpegName}.7z`
if (!(await fs.exists(config.ffmpegRealname)) && sevenZipPath) {
await $`'${wgetPath}' -O -nc --continue --no-check-certificate --show-progress ${config.windows.ffmpegUrl} -O ${config.windows.ffmpegName}.7z`
await $`'${sevenZipPath}' x ${config.windows.ffmpegName}.7z`
await $`mv ${config.windows.ffmpegName} ${config.ffmpegRealname}`
await $`rm -rf ${config.windows.ffmpegName}.7z`
await $`mv ${config.ffmpegRealname}/lib/x64/* ${config.ffmpegRealname}/lib/`
Expand All @@ -188,7 +185,7 @@ if (platform == 'windows') {

if (!(await fs.exists('tesseract'))) {
console.log('Setting up Tesseract for Windows...')
await $`${wgetPath} -nc --no-check-certificate --show-progress ${tesseractUrl} -O ${tesseractInstaller}`
await $`'${wgetPath}' -O -nc --continue --no-check-certificate --show-progress ${tesseractUrl} -O ${tesseractInstaller}`
await $`"${process.cwd()}\\${tesseractInstaller}" /S /D=C:\\Program Files\\Tesseract-OCR`
await $`rm ${tesseractInstaller}`
// Replace the mv command with xcopy
Expand All @@ -204,12 +201,13 @@ if (platform == 'windows') {
process.env.PATH = `${process.cwd()}\\tesseract;${process.env.PATH}`

// Setup ONNX Runtime
const unzipPath = await exePath("unzip");
const onnxRuntimeName = "onnxruntime-win-x64-gpu-1.19.2";
const onnxRuntimeLibs = `${onnxRuntimeName}.zip`;
const onnxRuntimeUrl = `https://github.com/microsoft/onnxruntime/releases/download/v1.19.2/${onnxRuntimeLibs}`
if (!(await fs.exists(onnxRuntimeName))) {
if (!(await fs.exists(onnxRuntimeName)) && unzipPath) {
console.log('Setting up ONNX Runtime libraries for Windows...')
await $`${wgetPath} -nc --no-check-certificate --show-progress ${onnxRuntimeUrl} -O ${onnxRuntimeLibs}`
await $`'${wgetPath}' -O -nc --continue --no-check-certificate --show-progress ${onnxRuntimeUrl} -O ${onnxRuntimeLibs}`
await $`unzip ${onnxRuntimeLibs} || tar -xf ${onnxRuntimeLibs} || echo "Done extracting"`;
await $`rm -rf ${onnxRuntimeLibs} || rm ${onnxRuntimeLibs} -Recurse -Force || echo "Done cleaning up zip"`;
console.log('ONNX Runtime libraries for Windows set up successfully.')
Expand All @@ -219,8 +217,8 @@ if (platform == 'windows') {

// Setup OpenBlas
if (!(await fs.exists(config.openblasRealname)) && hasFeature('openblas')) {
await $`${wgetPath} -nc --show-progress ${config.windows.openBlasUrl} -O ${config.windows.openBlasName}.zip`
await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.openBlasName}.zip -o${config.openblasRealname}`
await $`'${wgetPath}' -O -nc --continue --show-progress ${config.windows.openBlasUrl} -O ${config.windows.openBlasName}.zip`
await $`${sevenZipPath} x ${config.windows.openBlasName}.zip -o${config.openblasRealname}`
await $`rm ${config.windows.openBlasName}.zip`
fs.cp(path.join(config.openblasRealname, 'include'), path.join(config.openblasRealname, 'lib'), { recursive: true, force: true })
// It tries to link only openblas.lib but our is libopenblas.lib`
Expand All @@ -229,16 +227,21 @@ if (platform == 'windows') {

// Setup CLBlast
if (!(await fs.exists(config.clblastRealname)) && !hasFeature('cuda')) {
await $`${wgetPath} -nc --show-progress ${config.windows.clblastUrl} -O ${config.windows.clblastName}.zip`
await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.clblastName}.zip` // 7z file inside
await $`"C:\\Program Files\\7-Zip\\7z.exe" x ${config.windows.clblastName}.7z` // Inner folder
await $`'${wgetPath}' -O -nc --continue --show-progress ${config.windows.clblastUrl} -O ${config.windows.clblastName}.zip`
await $`'${sevenZipPath}' x ${config.windows.clblastName}.zip` // 7z file inside
await $`'${sevenZipPath}' x ${config.windows.clblastName}.7z` // Inner folder
await $`mv ${config.windows.clblastName} ${config.clblastRealname}`
await $`rm ${config.windows.clblastName}.zip`
await $`rm ${config.windows.clblastName}.7z`
}

// Setup vcpkg packages
await $`C:\\vcpkg\\vcpkg.exe install ${config.windows.vcpkgPackages}`.quiet()
// Setup vcpkg packages, requires VCPKG_ROOT env var
try {
await $`C:\\vcpkg\\vcpkg.exe install ${config.windows.vcpkgPackages}`
} catch (error) {
await $`vcpkg.exe install ${config.windows.vcpkgPackages}`
}

}

async function getMostRecentBinaryPath(targetArch, paths) {
Expand Down
12 changes: 6 additions & 6 deletions screenpipe-server/src/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ async fn start_ffmpeg_process(output_file: &str, fps: f64) -> Result<Child, anyh

if env::consts::OS == "windows" {
// TODO switch back to libx264 when ffmpeg is updated in pre_build.js
// Use MPEG-4 encoder for Windows
// Use H264_MF encoder for Windows
args.extend_from_slice(&[
"-vcodec",
"mpeg4",
"-q:v",
"5", // Adjust quality (1-31, lower is better)
"-preset",
"-vcodec",
"h264_mf",
"-q:v",
"5",
"-preset",
"ultrafast",
]);
} else {
Expand Down