#ffmpeg #ffi #binding #audio #video


A Rust crate that exposes FFmpeg's power as much as possible

15 releases (breaking)

0.12.0+ffmpeg.5.1 Sep 12, 2022
0.11.0 Jun 13, 2022
0.10.0 Jun 12, 2022
0.7.0 Nov 11, 2021
0.1.0 Oct 31, 2020

#14 in Video

Download history 63/week @ 2022-10-20 82/week @ 2022-10-27 76/week @ 2022-11-03 65/week @ 2022-11-10 46/week @ 2022-11-17 43/week @ 2022-11-24 28/week @ 2022-12-01 73/week @ 2022-12-08 61/week @ 2022-12-15 44/week @ 2022-12-22 53/week @ 2022-12-29 53/week @ 2023-01-05 44/week @ 2023-01-12 48/week @ 2023-01-19 61/week @ 2023-01-26 54/week @ 2023-02-02

232 downloads per month
Used in pizzicato

MIT license



Doc Crates.io CI

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.

Getting started

FFmpeg compilation

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)

# macOS
zsh utils/mac_ffmpeg.rs
# Linux
bash utils/linux_ffmpeg.rs
# Windows
# You need a Linux machine for cross compiling, then copy the artifact to your
# Windows machine.
bash utils/windows_ffmpeg.rs

Rsmpeg demo

Ensure that you have compiled the FFmpeg.

Start by adding rsmpeg to your Cargo.toml file:

rsmpeg = "0.11"

Write your simple media file info dumper:

use std::ffi::{CStr, CString};
use std::error::Error;
use rsmpeg::avformat::AVFormatContextInput;

fn dump_av_info(path: &CStr) -> Result<(), Box<dyn Error>> {
    let mut input_format_context = AVFormatContextInput::open(path)?;
    input_format_context.dump(0, path)?;

fn main() {

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).

# macOS & Linux
export FFMPEG_PKG_CONFIG_PATH=xxx/ffmpeg_build/lib/pkgconfig
# Windows
set FFMPEG_PKG_CONFIG_PATH=xxx/ffmpeg_build/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.

Advanced usage

  1. FFmpeg linking: refer to rusty_ffmpeg's documentation for how to use environment variables to statically or dynamically link FFmpeg.

  2. Advanced usage of rsmpeg: Check out the tests and examples folder.

Dependency version

Supported FFmpeg version is 5.1.

Minimum Supported Rust Version is 1.62.0(Stable channel).


Thanks for your contributions!


~102K SLoC