Skip to content

Commit

Permalink
Add ffmpeg example
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianEddy committed Oct 23, 2023
1 parent 7ec055e commit 37f5a07
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Instance {
width: usize,
height: usize,
stab: StabilizationManager,
time_scale: Option<f64>,
// Params
path: String,
smoothness: f64,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 37f5a07

Please sign in to comment.