Expand description
§ez-ffmpeg
ez-ffmpeg provides a safe and ergonomic Rust interface for FFmpeg integration. By abstracting away much of the raw C API complexity, It abstracts the complexity of the raw C API, allowing you to configure media pipelines, perform transcoding and filtering, and inspect streams with ease.
§Crate Layout
-
core
: The foundational module that contains the main building blocks for configuring and running FFmpeg pipelines. This includes:Input
/Output
: Descriptors for where media data comes from and goes to (files, URLs, custom I/O callbacks, etc.).FilterComplex
andFrameFilter
: Mechanisms for applying FFmpeg filter graphs or custom transformations.container_info
: Utilities to extract information about the container, such as duration and format details.stream_info
: Utilities to query media metadata (duration, codecs, etc.).hwaccel
: Helpers for enumerating and configuring hardware-accelerated video codecs (CUDA, VAAPI, VideoToolbox, etc.).codec
: Tools to list and inspect available encoders/decoders.device
: Utilities to discover system cameras, microphones, and other input devices.filter
: Query FFmpeg’s built-in filters and infrastructure for building custom frame-processing filters.context
: HousesFfmpegContext
for assembling an FFmpeg job.scheduler
: ProvidesFfmpegScheduler
which manages the lifecycle of that job.
-
opengl
(feature"opengl"
): Offers GPU-accelerated OpenGL filters, letting you provide a fragment shader and apply effects to video frames in a high-performance way without manually managing the GL context. -
rtmp
(feature"rtmp"
): Includes an embedded RTMP server,EmbedRtmpServer
, which can receive data directly from memory instead of over a network. Handy for local tests or simple streaming scenarios. -
flv
(feature"flv"
): Provides data structures and helpers for handling FLV containers, useful if you’re working with RTMP or other FLV-based workflows.
§Basic Usage
For a simple pipeline, you typically do the following:
- Build a
FfmpegContext
by specifying at least one input and one output. Optionally, add filter descriptions (filter_desc
) or attachFrameFilter
pipelines at either the input (post-decode) or the output (pre-encode) stage. - Create an
FfmpegScheduler
from that context, then callstart()
andwait()
(or.await
if you enable the"async"
feature) to run the job.
use ez_ffmpeg::FfmpegContext;
use ez_ffmpeg::FfmpegScheduler;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// 1. Build the FFmpeg context
let context = FfmpegContext::builder()
.input("input.mp4")
.filter_desc("hue=s=0") // Example filter: desaturate
.output("output.mov")
.build()?;
// 2. Run it via FfmpegScheduler (sync mode)
let result = FfmpegScheduler::new(context)
.start()?
.wait();
result?; // If any error occurred, propagate it
Ok(())
}
§Feature Flags
ez-ffmpeg
uses Cargo features to provide optional functionality. By default, no optional
features are enabled, allowing you to keep dependencies minimal. You can enable features as needed
in your Cargo.toml
:
[dependencies.ez-ffmpeg]
version = "*"
features = ["opengl", "rtmp", "flv", "async"]
§Core Features
opengl
: Enables OpenGL-based filters for GPU-accelerated processing.rtmp
: Enables an embedded RTMP server for local streaming scenarios.flv
: Adds FLV container parsing and handling.async
: Makes theFfmpegScheduler
wait method asynchronous (you can.await
it).static
: Uses static linking for FFmpeg libraries (viaffmpeg-next/static
).
§License Notice
ez-ffmpeg is distributed under the WTFPL (Do What The F*ck You Want To Public License). You are free to use, modify, and distribute this software.
Note: FFmpeg itself is subject to its own licensing terms. When enabling features that incorporate FFmpeg components, please ensure that your usage complies with FFmpeg’s license.
Re-exports§
pub use self::core::context::ffmpeg_context::FfmpegContext;
pub use self::core::context::input::Input;
pub use self::core::context::output::Output;
pub use self::core::scheduler::ffmpeg_scheduler::FfmpegScheduler;
pub use self::core::container_info;
pub use self::core::stream_info;
pub use self::core::device;
pub use self::core::hwaccel;
pub use self::core::codec;
pub use self::core::filter;
Modules§
- core
- The core module provides the foundational building blocks for configuring and running FFmpeg pipelines. It encompasses:
- error
- flv
- The FLV module contains data structures and tools to parse or handle FLV containers. It helps convert raw media data into FLV tags, making it easier to integrate with FFmpeg-based pipelines or RTMP streaming flows where FLV is the underlying format.
- opengl
- The OpenGL module provides a simplified approach to apply OpenGL-based filters/effects to video frames without manually dealing with OpenGL context creation or lifecycle management. Simply provide a fragment shader, and this module handles the details for you.
- rtmp
- The RTMP module includes an embedded RTMP server (
EmbedRtmpServer
) that can receive data directly from memory—bypassing actual network sockets—to facilitate local or test streaming scenarios. It is inspired byrml_rtmp
’s threaded RTMP server. - util