rsmpeg
is a thin&safe layer above the FFmpeg's Rust bindings, it's main goal is safely exposing FFmpeg inner APIs in Rust as much as possible.
Taking advantage of Rust's language design, you can build robust multi-media projects even quicker than using FFmpeg's C API.
Supported FFmpeg versions are:
- 4.3
- 4.4
- 5.*
(Enabled by feature ffmpeg5
)
- 6.*
(Enabled by feature ffmpeg6
).
Minimum Supported Rust Version is 1.64.0(Stable channel).
To use your first rsmpeg demo, you need to compile your FFmpeg: 1. https://github.com/ffmpeg/ffmpeg. 2. https://trac.ffmpeg.org/wiki/CompilationGuide
If you find the compilation complicated, there are some helpful compiling scripts for you (under the utils
folder).
To build a FFmpeg with some common parameters: (don't forget to install the build dependencies)
```bash
zsh utils/mac_ffmpeg.rs
bash utils/linux_ffmpeg.rs
bash utils/windows_ffmpeg.rs ```
These scripts build latest stable FFmpeg by default. You can build specific FFmpeg version explicitly:
```bash
zsh utils/mac_ffmpeg.rs release/5.0 ```
Ensure that you have compiled the FFmpeg.
Start by adding rsmpeg
to your Cargo.toml
file:
rust
[dependencies]
rsmpeg = "0.14.1"
Write your simple media file info dumper:
```rust use std::ffi::{CStr, CString}; use std::error::Error; use rsmpeg::avformat::AVFormatContextInput;
fn dumpavinfo(path: &CStr) -> Result<(), Box
fn main() { dumpavinfo(&CString::new("./test.jpg").unwrap()).unwrap(); } ```
Prepare a simple image in your current folder:
Run with FFMPEG_PKG_CONFIG_PATH
set to the pkgconfig file path (Absolute path!) in your artifact folder (xxx/ffmpeg_build/lib/pkgconfig
).
```bash
export FFMPEGPKGCONFIGPATH=xxx/ffmpegbuild/lib/pkgconfig
set FFMPEGPKGCONFIGPATH=xxx/ffmpegbuild/lib/pkgconfig
cargo run ```
Then it works:
Input #0, image2, from './test.jpg':
Duration: 00:00:00.04, start: 0.000000, bitrate: 1390 kb/s
Stream #0:0: Video: mjpeg, none, 25 fps, 25 tbr, 25 tbn, 25 tbc
(A single image's duration under 25fps is 0.04s)
You can also put any video or audio file here, this program will dump the media info for you.
FFmpeg linking: refer to rusty_ffmpeg
's documentation for how to use environment variables to statically or dynamically link FFmpeg.
Advanced usage of rsmpeg: Check out the tests
and examples
folder.
Thanks for your contributions!