Skip to content

Commit

Permalink
Revisit README
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Jul 22, 2024
1 parent a160b66 commit 649c157
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Downloads](https://img.shields.io/crates/d/rusty_ffmpeg)](https://lib.rs/crates/rusty_ffmpeg)
[![CI](https://github.com/CCExtractor/rusty_ffmpeg/workflows/CI/badge.svg?branch=master&style=flat-square)](https://github.com/CCExtractor/rusty_ffmpeg/actions)

Cross platform FFI bindings for FFmpeg inner libraries. This is a crate that:
Cross platform FFI bindings for FFmpeg internal libraries. This is a crate that:

1. Links FFmpeg libraries for you.
2. Generates Rust binding for FFmpeg libraries.
Expand All @@ -16,37 +16,43 @@ To use this crate, you need to set several environment variables.

### The simplest usage:

#### *nix
#### Linux, macOS..(*nix)

Build ffmpeg statically and set `FFMPEG_PKG_CONFIG_PATH` to the path of the generated FFmpeg `pkg-config` files. And you don't need to set other environment variables for static linking.
If you have FFmpeg installed with package manager, import `rusty_ffmpeg` with feature `link_system_ffmpeg`. Then it should work.

(Hint: setting `FFMPEG_PKG_CONFIG_PATH` to some placeholder value will leave a `rusty_ffmpeg` probing system library.)
If you built FFmpeg from source, set `FFMPEG_PKG_CONFIG_PATH` to the path of the generated FFmpeg `pkg-config` directory. Then it should work.

#### Windows

`rusty_ffmpeg` can link FFmpeg using `vcpkg`. Install [`vcpkg`](https://github.com/microsoft/vcpkg), check [documentation of the vcpkg *crate*](https://docs.rs/vcpkg) for the environment variables to set, then it works.
`rusty_ffmpeg` can link FFmpeg using `vcpkg`:
1. Install [`vcpkg`](https://github.com/microsoft/vcpkg), check [documentation of the vcpkg *crate*](https://docs.rs/vcpkg) for the environment variables to set.
2. Import `rusty_ffmpeg` with feature `link_vcpkg_ffmpeg`, Then it should work.

### Fine-grained usage:

You need to set several environment variables for both linking and binding generating procedures.
You need to set several environment variables for both the linking and binding generating procedures.

#### To link:
#### To link prebuilt libraries:

1. Dynamic linking with pre-built dylib: Set `FFMPEG_DLL_PATH` to the path of `dll` or `so`. (Windows: Put corresponding `.lib` file next to the `.dll` file.)
1. Dynamic linking with pre-built dylib: Set `FFMPEG_DLL_PATH` to the path of `dll` or `so` files. (Windows: Put corresponding `.lib` file next to the `.dll` file.)

2. Static linking with pre-built staticlib: Set `FFMPEG_LIBS_DIR` to the path of the FFmpeg pre-built libs directory.
2. Static linking with pre-built staticlib: Set `FFMPEG_LIBS_DIR` to the path of FFmpeg pre-built libs directory.

#### To generate bindings:

1. Compile-time binding generation([requires the `Clang` dylib](https://github.com/KyleMayes/clang-sys/blob/c9ae24a7a218e73e1eccd320174349eef5a3bd1a/build.rs#L23)): Set `FFMPEG_INCLUDE_DIR` to the path to the header files for binding generation.
1. Compile-time binding generation([requires the `Clang` dylib](https://github.com/KyleMayes/clang-sys/blob/c9ae24a7a218e73e1eccd320174349eef5a3bd1a/build.rs#L23)): Set `FFMPEG_INCLUDE_DIR` to the path of the header files for binding generation.

2. Use your pre-built binding: Set `FFMPEG_BINDING_PATH` to the pre-built binding file. The pre-built binding is usually copied from the `OUT_DIR` of the compile-time binding generation, by using it you don't need to regenerate the same binding file again and again.
2. Use your prebuilt binding: Set `FFMPEG_BINDING_PATH` to the pre-built binding file. The pre-built binding is usually copied from the `OUT_DIR` of the compile-time binding generation, using it will prevent the need to regenerate the same binding file repeatedly.

### Linking FFmpeg installed by package manager on (*nix)

You can enable system-wide FFmpeg linking by enabling feature `link_system_ffmpeg`.
You can link FFmpeg libraries installed by package manager by enabling feature `link_system_ffmpeg` (which uses pkg-config underneath).

### Use specific FFmpeg version
### Linking FFmpeg installed by vcpkg

You can link FFmpeg libraries installed by vcpkg by enabling feature `link_vcpkg_ffmpeg` on Windows, macOS, and Linux.

### Use a specific FFmpeg version

- Do nothing when you are using FFmpeg `4.*`
- Enable `ffmpeg5` feature when you are using FFmpeg `5.*`
Expand All @@ -55,4 +61,4 @@ You can enable system-wide FFmpeg linking by enabling feature `link_system_ffmpe

## Attention

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 has some typical ffmpeg compilation and use cases for you to check. File an issue if you still have any problem.
FFI is not that easy, especially when you are dealing with a big old C project. Don't get discouraged if you encounter some problems. The CI check already has some typical ffmpeg compilation and use cases for you to check. File an issue if you still have any problems.

0 comments on commit 649c157

Please sign in to comment.