1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
// In test builds, libtest-generated code references test items through the
// deprecated `opengl` module path, which a file-level allow cannot cover.
// Safety-hygiene lint (clippy-only; does not affect normal builds). Every
// public `unsafe fn` must document its contract with a `# Safety` section.
// Broader gates (`clippy::undocumented_unsafe_blocks`, `unsafe_op_in_unsafe_fn`)
// are deferred until the pre-existing unsafe-doc/import backlog is paid down.
//! # ez-ffmpeg
//!
//! **ez-ffmpeg** provides a safe and ergonomic Rust interface for [FFmpeg](https://ffmpeg.org)
//! 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` and [`FrameFilter`](filter::frame_filter::FrameFilter): 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`: Houses [`FfmpegContext`] for assembling an FFmpeg job.
//! - `scheduler`: Provides [`FfmpegScheduler`] which manages the lifecycle of that job.
//!
//! - **`wgpu_filter`** (feature `"wgpu"`): GPU-accelerated frame filters via wgpu
//! (Vulkan/Metal/DX12/GL). Provide a WGSL fragment shader and apply effects with
//! correct color handling, headless operation, and GPU/CPU overlap.
//!
//! - **`opengl`** (feature `"opengl"`, deprecated): The former OpenGL filter path,
//! superseded by `wgpu_filter`. Kept for backward compatibility; it requires a
//! display connection and will be removed in a future major release.
//!
//! - **`rtmp`** (feature `"rtmp"`): Embedded RTMP server `EmbedRtmpServer` built for production streaming,
//! using native epoll/kqueue/WSAPoll via libc FFI (edge-triggered on Linux/macOS, level-triggered on Windows),
//! zero-copy GOP fanout with `Arc<[FrameData]>`, and tiered backpressure (1/2/4MB) on a 2-thread model;
//! 10,000+ conns on Linux/macOS (8,000 on Windows) with in-process ingest (no TCP between FFmpeg and server).
//!
//! - **`flv`** (feature `"flv"`): Provides data structures and helpers for handling FLV
//! containers, useful if you’re working with RTMP or other FLV-based workflows.
//!
//! - **`subtitle`** (feature `"subtitle"`): Burns ASS/SRT subtitles onto video frames inside
//! the frame pipeline with a pure-Rust renderer — independent of whether the linked FFmpeg
//! was built with `--enable-libass`. Accepts subtitle files or in-memory scripts and
//! explicit font files.
//!
//! ## Basic Usage
//!
//! For a simple pipeline, you typically do the following:
//!
//! 1. Build a [`FfmpegContext`] by specifying at least one [input](Input)
//! and one [output](Output). Optionally, add filter descriptions
//! (`filter_desc`) or attach [`FrameFilter`](filter::frame_filter::FrameFilter) pipelines at either the input (post-decode)
//! or the output (pre-encode) stage.
//! 2. Create an [`FfmpegScheduler`] from that context, then call `start()` and `wait()` (or `.await`
//! if you enable the `"async"` feature) to run the job.
//!
//! ```rust,ignore
//! 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`:
//!
//! ```toml
//! [dependencies.ez-ffmpeg]
//! version = "*"
//! features = ["wgpu", "rtmp", "flv", "async"]
//! ```
//!
//! ### Core Features
//!
//! - **`wgpu`**: Enables wgpu-based GPU filters (WGSL shaders, headless-capable).
//! - **`opengl`** (deprecated): Enables the former OpenGL-based filters; superseded by `wgpu`.
//! - **`rtmp`**: Embedded RTMP server tuned for scale (10,000+ conns on Linux/macOS, 8,000 on Windows),
//! native epoll/kqueue/WSAPoll IO (edge-triggered on Linux/macOS), zero-copy GOP, and in-process ingest
//! that avoids TCP between FFmpeg and server.
//! - **`flv`**: Adds FLV container parsing and handling.
//! - **`subtitle`**: Native ASS/SRT subtitle burn-in rendered in pure Rust — no system
//! libraries beyond FFmpeg itself (see the `subtitle` module docs).
//! - **`async`**: Makes the [`FfmpegScheduler`] wait method asynchronous (you can `.await` it).
//! - **`static`**: Uses static linking for FFmpeg libraries (via `ffmpeg-next/static`).
//!
//! ## Relationship to the FFmpeg CLI
//!
//! The transcoding pipeline (demux -> decode -> filter -> encode -> mux) is
//! ported from the FFmpeg CLI sources, `fftools/ffmpeg` of **FFmpeg 7.x**:
//! function names, timestamp handling and scheduling semantics follow that
//! release, and code comments cite the corresponding fftools file and line
//! (line numbers refer to the FFmpeg `n7.1` tag).
//! If you know `ffmpeg_demux.c` or `ffmpeg_filter.c`, grepping this crate
//! for the same function names (`ts_fixup`, `video_sync_process`,
//! `enc_open`, `mux_fixup_ts`, ...) lands in the equivalent Rust.
//!
//! Not every CLI feature is implemented. Notable gaps: progress/stats
//! reporting (`-progress`), sub2video (rendering bitmap subtitles into
//! video), `-shortest` cross-stream sync, bitstream filters (`-bsf`),
//! keyframe forcing (`-force_key_frames`), `-fix_sub_duration`, two-pass
//! encoding, and attachments. Unsupported paths fail with explicit errors
//! rather than approximations.
//!
//! ## Logging
//!
//! FFmpeg's own diagnostics (av_log) are redirected into the Rust `log`
//! facade under the [`FFMPEG_LOG_TARGET`] target. Without a logger installed
//! (env_logger, tracing-log, ...) all FFmpeg messages are silently dropped —
//! including decoder errors that explain a failing job. Use
//! [`set_ffmpeg_log_level`] to bound the forwarded verbosity and
//! `Input::set_log_level_offset` to shift it per input.
//!
//! ## License Notice
//!
//! ez-ffmpeg is licensed under your choice of MIT, Apache-2.0, or MPL-2.0
//! (matching the `license` field in Cargo.toml).
//!
//! **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.
/// Internal RAII wrappers concentrating raw FFmpeg FFI pointers (Rung-2 boundary).
pub
pub use FfmpegContext;
pub use Input;
pub use Output;
pub use FfmpegScheduler;
pub use container_info;
pub use stream_info;
pub use ;
pub use packet_scanner;
pub use device;
pub use hwaccel;
pub use codec;
pub use filter;
pub use analysis;
pub use recipes;
pub use AVRational;
pub use AVMediaType;
pub use Frame;
use declare_surfman;
declare_surfman!;