ez_ffmpeg/
lib.rs

1//! # ez-ffmpeg
2//!
3//! **ez-ffmpeg** provides a safe and ergonomic Rust interface for [FFmpeg](https://ffmpeg.org)
4//! integration. By abstracting away much of the raw C API complexity,
5//! It abstracts the complexity of the raw C API, allowing you to configure media pipelines,
6//! perform transcoding and filtering, and inspect streams with ease.
7//!
8//! ## Crate Layout
9//!
10//! - **`core`**: The foundational module that contains the main building blocks for configuring
11//!   and running FFmpeg pipelines. This includes:
12//!   - `Input` / `Output`: Descriptors for where media data comes from and goes to (files, URLs,
13//!     custom I/O callbacks, etc.).
14//!   - `FilterComplex` and [`FrameFilter`](filter::frame_filter::FrameFilter): Mechanisms for applying FFmpeg filter graphs or
15//!     custom transformations.
16//!   - `container_info`: Utilities to extract information about the container, such as duration and format details.
17//!   - `stream_info`: Utilities to query media metadata (duration, codecs, etc.).
18//!   - `hwaccel`: Helpers for enumerating and configuring hardware-accelerated video codecs
19//!     (CUDA, VAAPI, VideoToolbox, etc.).
20//!   - `codec`: Tools to list and inspect available encoders/decoders.
21//!   - `device`: Utilities to discover system cameras, microphones, and other input devices.
22//!   - `filter`: Query FFmpeg's built-in filters and infrastructure for building custom frame-processing filters.
23//!   - `context`: Houses [`FfmpegContext`] for assembling an FFmpeg job.
24//!   - `scheduler`: Provides [`FfmpegScheduler`] which manages the lifecycle of that job.
25//!
26//! - **`opengl`** (feature `"opengl"`): Offers GPU-accelerated OpenGL filters, letting you
27//!   provide a fragment shader and apply effects to video frames in a high-performance way
28//!   without manually managing the GL context.
29//!
30//! - **`rtmp`** (feature `"rtmp"`): Includes an embedded RTMP server, `EmbedRtmpServer`, which
31//!   can receive data directly from memory instead of over a network. Handy for local tests
32//!   or simple streaming scenarios.
33//!
34//! - **`flv`** (feature `"flv"`): Provides data structures and helpers for handling FLV
35//!   containers, useful if you’re working with RTMP or other FLV-based workflows.
36//!
37//! ## Basic Usage
38//!
39//! For a simple pipeline, you typically do the following:
40//!
41//! 1. Build a [`FfmpegContext`] by specifying at least one [input](Input)
42//!    and one [output](Output). Optionally, add filter descriptions
43//!    (`filter_desc`) or attach [`FrameFilter`](filter::frame_filter::FrameFilter) pipelines at either the input (post-decode)
44//!    or the output (pre-encode) stage.
45//! 2. Create an [`FfmpegScheduler`] from that context, then call `start()` and `wait()` (or `.await`
46//!    if you enable the `"async"` feature) to run the job.
47//!
48//! ```rust
49//! use ez_ffmpeg::FfmpegContext;
50//! use ez_ffmpeg::FfmpegScheduler;
51//!
52//! fn main() -> Result<(), Box<dyn std::error::Error>> {
53//!     // 1. Build the FFmpeg context
54//!     let context = FfmpegContext::builder()
55//!         .input("input.mp4")
56//!         .filter_desc("hue=s=0") // Example filter: desaturate
57//!         .output("output.mov")
58//!         .build()?;
59//!
60//!     // 2. Run it via FfmpegScheduler (sync mode)
61//!     let result = FfmpegScheduler::new(context)
62//!         .start()?
63//!         .wait();
64//!     result?; // If any error occurred, propagate it
65//!     Ok(())
66//! }
67//! ```
68//!
69//! ## Feature Flags
70//!
71//! **`ez-ffmpeg`** uses Cargo features to provide optional functionality. By default, no optional
72//! features are enabled, allowing you to keep dependencies minimal. You can enable features as needed
73//! in your `Cargo.toml`:
74//!
75//! ```toml
76//! [dependencies.ez-ffmpeg]
77//! version = "*"
78//! features = ["opengl", "rtmp", "flv", "async"]
79//! ```
80//!
81//! ### Core Features
82//!
83//! - **`opengl`**: Enables OpenGL-based filters for GPU-accelerated processing.
84//! - **`rtmp`**: Enables an embedded RTMP server for local streaming scenarios.
85//! - **`flv`**: Adds FLV container parsing and handling.
86//! - **`async`**: Makes the [`FfmpegScheduler`] wait method asynchronous (you can `.await` it).
87//! - **`static`**: Uses static linking for FFmpeg libraries (via `ffmpeg-next/static`).
88//!
89//! ## License Notice
90//!
91//! ez-ffmpeg is distributed under the WTFPL (Do What The F*ck You Want To Public License).
92//! You are free to use, modify, and distribute this software.
93//!
94//! **Note:** FFmpeg itself is subject to its own licensing terms. When enabling features that incorporate FFmpeg components,
95//! please ensure that your usage complies with FFmpeg's license.
96
97pub mod core;
98pub mod util;
99pub mod error;
100
101pub use self::core::context::ffmpeg_context::FfmpegContext;
102pub use self::core::context::input::Input;
103pub use self::core::context::output::Output;
104pub use self::core::scheduler::ffmpeg_scheduler::FfmpegScheduler;
105pub use self::core::container_info;
106pub use self::core::stream_info;
107pub use self::core::device;
108pub use self::core::hwaccel;
109pub use self::core::codec;
110pub use self::core::filter;
111
112pub use ffmpeg_sys_next::AVRational;
113pub use ffmpeg_sys_next::AVMediaType;
114
115
116#[cfg(feature = "opengl")]
117pub mod opengl;
118#[cfg(feature = "opengl")]
119use surfman::declare_surfman;
120#[cfg(feature = "opengl")]
121declare_surfman!();
122
123#[cfg(feature = "rtmp")]
124pub mod rtmp;
125
126#[cfg(feature = "flv")]
127pub mod flv;