Skip to content

Commit

Permalink
Check for ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
MatijaNovosel committed Jun 23, 2023
1 parent 1d13e65 commit e32cc21
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"rust-analyzer.linkedProjects": ["src-tauri/Cargo.toml"],
"rust-analyzer.diagnostics.disabled": ["unresolved-proc-macro"]
"rust-analyzer.diagnostics.disabled": ["unresolved-proc-macro"],
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer"
}
}
77 changes: 53 additions & 24 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,45 +1,74 @@
#![allow(non_snake_case)]
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

use std::path::Path;
use std::env;
use std::process::Command;
use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::process::Command;

fn findIt<P>(exe_name: P) -> Option<PathBuf>
where
P: AsRef<Path>,
{
env::var_os("PATH").and_then(|paths| {
env::split_paths(&paths)
.filter_map(|dir| {
let full_path = dir.join(&exe_name);
if full_path.is_file() {
Some(full_path)
} else {
None
}
})
.next()
})
}

#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
format!("Hello, {}! You've been greeted from Rust!", name)
}

#[tauri::command]
fn convert(fileName: &str) -> Vec<String> {
// ffmpeg -i output.webm -c copy -fflags +genpts video.mp4
let dir = env::temp_dir();
let in_dir = format!("{}{}", dir.display(), fileName);
let out_dir = format!("{}video.mp4", dir.display());
let b = Path::new(&in_dir).is_file();
if b {
let mut child = Command::new("ffmpeg.exe")
.args(["-i", &in_dir, "-c", "copy", "-fflags", "+genpts", &out_dir])
.spawn()
.expect("failed to execute process");
child.wait().expect("failed to wait on child");
return vec![in_dir.into(), out_dir.into()];
}
return vec!["".to_string(), "".to_string()];
// ffmpeg -i output.webm -c copy -fflags +genpts video.mp4
let dir = env::temp_dir();
let in_dir = format!("{}{}", dir.display(), fileName);
let out_dir = format!("{}video.mp4", dir.display());
let b = Path::new(&in_dir).is_file();
if b {
let mut child = Command::new("ffmpeg.exe")
.args(["-i", &in_dir, "-c", "copy", "-fflags", "+genpts", &out_dir])
.spawn()
.expect("failed to execute process");
child.wait().expect("failed to wait on child");
return vec![in_dir.into(), out_dir.into()];
}
return vec!["".to_string(), "".to_string()];
}

#[tauri::command]
fn save(convertedPath: &str, savePath: &str) -> () {
fs::rename(convertedPath, savePath).expect("Could not rename");
fs::rename(convertedPath, savePath).expect("Could not rename");
}

#[tauri::command]
fn ffmpegInstalled() -> bool {
return findIt("ffmpeg.exe") != None;
}

fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet, convert, save])
.run(tauri::generate_context!())
.expect("error while running tauri application");
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![
greet,
convert,
save,
ffmpegInstalled
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
12 changes: 11 additions & 1 deletion src/pages/Dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,12 @@ const convertFile = async (content?: Uint8Array) => {
}
};
const $export = () => {
const $export = async () => {
const installed = await ffmpegInstalled();
if (!installed) {
createToast("Cannot render, ffmpeg is not installed!", colors.red.darken1);
return;
}
const chunks: Blob[] = [];
const stream = recordCanvas.value!.captureStream(60);
recorder = new MediaRecorder(stream, {
Expand Down Expand Up @@ -861,6 +866,11 @@ const followCursor = ({ pageX }: MouseEvent) => {
}
};
const ffmpegInstalled = async () => {
const installed = await invoke<boolean>("ffmpegInstalled");
return installed;
};
const updateActiveObjectDimensions = () => {
const activeObject = fabricCanvas?.getActiveObject();
if (activeObject) {
Expand Down

0 comments on commit e32cc21

Please sign in to comment.