Skip to content

Commit 30052b6

Browse files
committed
Pick up lost branches, Update README.
1 parent f540d92 commit 30052b6

File tree

2 files changed

+31
-20
lines changed

2 files changed

+31
-20
lines changed

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,26 @@
55
[![Doc](https://docs.rs/rusty_ffmpeg/badge.svg)](https://docs.rs/rusty_ffmpeg)
66

77
Cross platform FFI bindings for FFmpeg inner libraries. This is a crate that:
8-
1. Generates Rust binding for FFmpeg libraries which can be used directly.
9-
2. Emits specific cargo metadata for linking FFmpeg libraries.
108

11-
## Building
9+
1. Linking FFmpeg libraries for you.
10+
2. Generates Rust binding for FFmpeg libraries.
1211

13-
### Generate and build the bindings:
12+
## Usage
1413

15-
1. Set(always) `FFMPEG_INCLUDE_DIR` to the path to the header files for generating bindings.
14+
To use this crate, you need to set several environment variables.
1615

17-
2. Set `FFMPEG_DLL_PATH` for dynamic linking with `dll` or `so`. (Windows: Put corresponding `.lib` file next to the `.dll` file.)
16+
### To link:
1817

19-
3. Set `FFMPEG_PKG_CONFIG_PATH` for static linking with `pkg-config` files.
18+
1. Dynamic linking with prebuilt dylib: Set `FFMPEG_DLL_PATH` to the path of `dll` or `so`. (Windows: Put corresponding `.lib` file next to the `.dll` file.)
2019

21-
4. Set `FFMPEG_LIBS_DIR` for static linking with static libs.
20+
2. Static linking with prebuilt staticlib: Set `FFMPEG_PKG_CONFIG_PATH` to the path of the FFmpeg package-config files or set `FFMPEG_LIB_DIR` to the path of the FFmpeg prebuilt libs directory.
2221

23-
FFMPEG_INCLUDE_DIR=${HOME}/ffmpeg_build/include FFPEG_LIBS_DIR=${HOME}/ffmpeg_build/lib cargo run --example slice
24-
FFMPEG_INCLUDE_DIR=${HOME}/ffmpeg_build/include FFMPEG_PKG_CONFIG_PATH=${HOME}/ffmpeg_build/lib/pkgconfig cargo run --example slice
22+
### To generate bindings:
23+
24+
1. Compile-time binding generation(requires clang dylib): Set `FFMPEG_INCLUDE_DIR` to the path to the header files for binding generation.
25+
26+
2. Use pre-built binding: Set `FFMPEG_BINDING_PATH` to the prebuilt binding file.
27+
28+
### Attention
29+
30+
FFI is not that easy, especially when you are dealing with a big old C project. Don't feel depressed when there are some problems. The CI check already have some typical use cases, you can check it. File an issue if you still have some problem.

build.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,9 @@ mod windows {
358358
}
359359

360360
fn dynamic_linking(env_vars: &EnvVars) {
361-
let ffmpeg_include_dir = env_vars.ffmpeg_include_dir.as_ref().unwrap();
362361
let ffmpeg_dll_path = env_vars.ffmpeg_dll_path.as_ref().unwrap();
363362

364-
let binding_file_path = &format!("{}/binding.rs", env_vars.out_dir.as_ref().unwrap());
363+
let output_binding_path = &format!("{}/binding.rs", env_vars.out_dir.as_ref().unwrap());
365364

366365
// Extract dll name and the dir the dll is in.
367366
let (ffmpeg_dll_name, ffmpeg_dll_dir) = {
@@ -383,11 +382,17 @@ fn dynamic_linking(env_vars: &EnvVars) {
383382
println!("cargo:rustc-link-lib=dylib={}", ffmpeg_dll_name);
384383
println!("cargo:rustc-link-search=native={}", ffmpeg_dll_dir);
385384

386-
generate_bindings(Some(&ffmpeg_include_dir), HEADERS.iter().cloned())
387-
.expect("Binding generation failed.")
388-
// Is it correct to generate binding to one file? :-/
389-
.write_to_file(binding_file_path)
390-
.expect("Cannot write binding to file.");
385+
if let Some(ffmpeg_binding_path) = env_vars.ffmpeg_binding_path.as_ref() {
386+
use_prebuilt_binding(ffmpeg_binding_path, output_binding_path);
387+
} else if let Some(ffmpeg_include_dir) = env_vars.ffmpeg_include_dir.as_ref() {
388+
generate_bindings(Some(&ffmpeg_include_dir), HEADERS.iter().cloned())
389+
.expect("Binding generation failed.")
390+
// Is it correct to generate binding to one file? :-/
391+
.write_to_file(output_binding_path)
392+
.expect("Cannot write binding to file.");
393+
} else {
394+
panic!("No binding generation method is set!");
395+
}
391396
}
392397

393398
fn static_linking(env_vars: &EnvVars) {
@@ -416,15 +421,15 @@ fn static_linking(env_vars: &EnvVars) {
416421
}
417422
} else if let Some(ffmpeg_libs_dir) = env_vars.ffmpeg_libs_dir.as_ref() {
418423
static_linking_with_libs_dir(&*LIBS, ffmpeg_libs_dir);
419-
420-
let ffmpeg_include_dir = env_vars.ffmpeg_include_dir.as_ref().unwrap();
421424
if let Some(ffmpeg_binding_path) = env_vars.ffmpeg_binding_path.as_ref() {
422425
use_prebuilt_binding(ffmpeg_binding_path, output_binding_path);
423-
} else {
426+
} else if let Some(ffmpeg_include_dir) = env_vars.ffmpeg_include_dir.as_ref() {
424427
generate_bindings(Some(&ffmpeg_include_dir), HEADERS.iter().cloned())
425428
.expect("Binding generation failed.")
426429
.write_to_file(output_binding_path)
427430
.expect("Cannot write binding to file.");
431+
} else {
432+
panic!("No binding generation method is set!");
428433
}
429434
} else {
430435
panic!("No linking method set!");

0 commit comments

Comments
 (0)