From 37f5a07cc3e6932c04abfd99b9e7245117ee3ca2 Mon Sep 17 00:00:00 2001 From: AdrianEddy Date: Tue, 24 Oct 2023 01:49:30 +0200 Subject: [PATCH] Add ffmpeg example --- Cargo.lock | 10 ---------- Cargo.toml | 1 - README.md | 7 +++++++ src/lib.rs | 16 +++++++++++++--- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 435d4ec..7b9ba07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1149,7 +1149,6 @@ dependencies = [ "cstr", "gyroflow-core", "log", - "win_dbg_logger", ] [[package]] @@ -3160,15 +3159,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8" -[[package]] -name = "win_dbg_logger" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d1b4c22244dc27534d81e2f6fc3efd6b20e50c010f177efc20b719ec759a779" -dependencies = [ - "log", -] - [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index f0ec43e..b2d8660 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,6 @@ log = "0.4" gyroflow-core = { git = "https://github.com/gyroflow/gyroflow.git", default-features = false, rev = "c551b2f", features = ["bundle-lens-profiles"] } #gyroflow-core = { path = "../gyroflow/src/core", default-features = false, features = ["bundle-lens-profiles"] } cstr = "0.2" -win_dbg_logger = "*" [features] default = ["use-opencl"] diff --git a/README.md b/README.md index 1e4630f..05ed0a6 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,13 @@ Some applications using frei0r, in which you can use this plugin: 1. Copy the plugin binary to `kdenlive/lib/frei0r-1/` 2. Copy [`frei0r_gyroflow.xml`](https://raw.githubusercontent.com/gyroflow/gyroflow-frei0r/main/frei0r_gyroflow.xml) to `kdenlive/bin/data/kdenlive/effects/` +# Usage + +### FFmpeg: +1. Create a folder somewhere, copy the plugin binary to it, and set environment variable `FREI0R_PATH` to that dir. For example on Windows: `set FREI0R_PATH=C:\effects\` +2. Run ffmpeg: `ffmpeg -i input_video.mp4 -vf "frei0r=gyroflow:C_DRIVE_SEP_projects_DIR_SEP_my_project.gyroflow|0.5|n" result.mp4` +3. Parameters are: `project_file_path|smoothness|stabilization_overview`. +4. Because ffmpoeg can't accept `:` or `/` in parameters, plugin will replace `_DRIVE_SEP_` with `:\` and `_DIR_SEP_` with `/`, so you can use parameter: `E_DRIVE_SEP_some_folder_DIR_SEP_my_project.gyroflow` for `E:\some_folder\my_project.gyroflow` # Building from source diff --git a/src/lib.rs b/src/lib.rs index 59cbdd2..6e8416e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ struct Instance { width: usize, height: usize, stab: StabilizationManager, + time_scale: Option, // Params path: String, smoothness: f64, @@ -88,7 +89,10 @@ extern "C" fn f0r_set_param_value(instance: f0r_instance_t, param: f0r_param_t, unsafe { match index { 0 => { // Project file - let path = std::ffi::CStr::from_ptr(*(param as *mut *mut std::ffi::c_char)).to_string_lossy().to_owned().to_string(); + let path = std::ffi::CStr::from_ptr(*(param as *mut *mut std::ffi::c_char)).to_string_lossy().to_owned() + .replace("_DRIVE_SEP_", ":/") + .replace("_DIR_SEP_", "/"); + if path != inst.path { inst.path = path.clone(); @@ -162,9 +166,15 @@ extern "C" fn f0r_get_param_value(instance: f0r_instance_t, param: f0r_param_t, #[no_mangle] extern "C" fn f0r_update(instance: f0r_instance_t, time: f64, inframe: *const u32, outframe: *mut u32) { if instance.is_null() { return; } - let inst = unsafe { Box::from_raw(instance as *mut Instance) }; + let mut inst = unsafe { Box::from_raw(instance as *mut Instance) }; + if time > 0.0 && inst.time_scale.is_none() { + // FFmpeg passes wrong units of `time` - it's in milliseconds instead of seconds + // If the second frame has `time` larger than 1 (second), then set the timescale to 0.001 to workaround that bug + inst.time_scale = Some(if time > 1.0 { 0.001 } else { 1.0 }); + } + let scale = inst.time_scale.unwrap_or(1.0); - let timestamp_us = (time * 1_000_000.0).round() as i64; + let timestamp_us = (time * 1_000_000.0 * scale).round() as i64; let org_ratio = { let params = inst.stab.params.read();