Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Wrap a standalone FFmpeg binary in an intuitive Iterator interface. 🏍

License

NotificationsYou must be signed in to change notification settings

nathanbabcock/ffmpeg-sidecar

Repository files navigation

GithubCrates.ioDocs.rsGithub Actions

Wrap a standalone FFmpeg binary in an intuitive Iterator interface.

Features

  • ✨ Minimal dependencies
  • ⚡ Automatic FFmpeg CLI download (if needed)
  • 🤗 Support for Windows, MacOS, and Linux
  • 🧪 Thoroughly unit tested

👉 Jump toGetting Started 👈

Motivation

The core goal of this project is to provide a method of interacting with any videoas if it were anarray of raw RGB frames.

Of course, that's what videois, fundamentally, but there is a whole pandora'sbox of complexity in terms of receiving and decoding video before you get there.

Using FFmpeg as the core engine provides interoperability between a massiverange of formats, containers, extensions, protocols, encoders, decoders, hardware accelerations, andmore.

Why CLI?

One method of using FFmpeg is low-level bindings to the code used inside the CLIitself -- there aregood crates inthe Rust ecosystem that do this.

Low level bindings have drawbacks, though:

  • Difficult, time-consuming build, toolchain, and dependencies, especially on Windows
  • Complexity, especially for beginners
  • You end up manually re-implementing a lot of the standard conversions you needfrom scratch

By wrapping the CLI, this crate avoids those downsides, and also solves some ofthe pain points that you would encounter if you were to use the CLI directly onits own:

  • Raw data can easily move in and out of FFmpeg instances, or pipe between them. Under the hood theyare moving across stdin and stdout.
  • Rich semantic information is recovered from the FFmpeg stderr logs, including:
    • Progress updates (frame #, timestamp, speed, bitrate, ...)
    • Input/output metadata and stream mappings
    • Warnings & errors
  • Argument presets and aliases with discoverable names through Intellisense/autocomplete

The only remaining downside is the size of the FFmpeg binary itself, but it'sless than 100MB when zipped. It can be automatically downloaded by the crate, soyou may choose to not even ship it with your own application and insteaddownload it at runtime.

Getting Started

Tip

Integrating with async Rust ortokio? Check outasync-ffmpeg-sidecar.

1. Cargo Install

cargo add ffmpeg-sidecar

2. Download FFmpeg

To automatically download & install a FFmpeg binary for your platform(Windows, MacOS, and Linux), call this function anywhere in your program:

ffmpeg_sidecar::download::auto_download().unwrap();

You can do this once to set up your dev environment, or include it as a featureof your client application.

To customize or extend the download, see/examples/download_ffmpeg.rs.

Examples

Hello world 👋

Read raw video frames.

use ffmpeg_sidecar::command::FfmpegCommand;fnmain() -> anyhow::Result<()>{// Run an FFmpeg command that generates a test videolet iter =FfmpegCommand::new()// <- Builder API like `std::process::Command`.testsrc()// <- Discoverable aliases for FFmpeg args.rawvideo()// <- Convenient argument presets.spawn()?// <- Ordinary `std::process::Child`.iter()?;// <- Blocking iterator over logs and output// Use a regular "for" loop to read decoded video datafor framein iter.filter_frames(){println!("frame: {}x{}", frame.width, frame.height);let _pixels:Vec<u8> = frame.data;// <- raw RGB pixels! 🎨}Ok(())}

Source:/examples/hello_world.rs

cargo run --example hello_world

H265 Transcoding

Decode H265, modify the decoded frames, and then write back to H265.

Source:/examples/h265_transcode.rs

cargo run --example h265_transcode

FFplay

Pipe an FFmpeg instance to FFplay for debugging purposes.

Source:/examples/ffplay_preview.rs

cargo run --example ffplay_preview

Named pipes

Pipe multiple outputs from FFmpeg into a Rust program.

Source:/examples/named_pipes.rs

cargo run --example named_pipes --features named_pipes

Others

For a myriad of other use cases, check any of theexamples, aswell as the unit tests in/src/test.rs.

See also

Inspired loosely by Node.jsfluent-ffmpeg, which doessomething similar in Javascript.

Usessetup-ffmpeg forGithub Actions and as a reference for the auto-download behavior.

📣 Pull Requests Welcome 📣

About

Wrap a standalone FFmpeg binary in an intuitive Iterator interface. 🏍

Topics

Resources

License

Stars

Watchers

Forks

Contributors14


[8]ページ先頭

©2009-2025 Movatter.jp