ProductPromotion
Logo

Rust

made by https://0x3d.site

GitHub - nathanbabcock/ffmpeg-sidecar: Wrap a standalone FFmpeg binary in an intuitive Iterator interface. 🏍
Wrap a standalone FFmpeg binary in an intuitive Iterator interface. 🏍 - nathanbabcock/ffmpeg-sidecar
Visit Site

GitHub - nathanbabcock/ffmpeg-sidecar: Wrap a standalone FFmpeg binary in an intuitive Iterator interface. 🏍

GitHub - nathanbabcock/ffmpeg-sidecar: Wrap a standalone FFmpeg binary in an intuitive Iterator interface. 🏍

FFmpeg Sidecar 🏍

Github | Crates.io | Docs.rs

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 to Getting Started 👈

Motivation

The core goal of this project is to provide a method of interacting with any video as if it were an array of raw RGB frames.

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

Using FFmpeg as the core engine provides interoperability between a massive range of formats, containers, extensions, protocols, encoders, decoders, hardware accelerations, and more.

Why CLI?

One method of using FFmpeg is low-level bindings to the code used inside the CLI itself -- there are good crates in the 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 need from scratch

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

  • Raw data can easily move in and out of FFmpeg instances, or pipe between them. Under the hood they are 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's less than 100MB when zipped. It can be automatically downloaded by the crate, so you may choose to not even ship it with your own application and instead download it at runtime.

Getting Started

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 feature of 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;

fn main() -> anyhow::Result<()> {
  // Run an FFmpeg command that generates a test video
  let 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 data
  for frame in 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 the examples, as well as the unit tests in /src/test.rs.

See also

Inspired loosely by Node.js fluent-ffmpeg, which does something similar in Javascript.

Uses setup-ffmpeg for Github Actions and as a reference for the auto-download behavior.

📣 Pull Requests Welcome 📣

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory