Skip to main content

rff/
lib.rs

1//! `rff` — the Remade FFmpeg (Rust) engine facade.
2//!
3//! This is the crate you depend on to *use* the project as a library. It pulls
4//! the layered crates together:
5//! * re-exports the core vocabulary ([`core`], [`codec`], [`format`]),
6//! * builds an [`Engine`] with every built-in codec and container registered,
7//! * exposes the high-level [`transcode`], [`probe`] and [`targets`] APIs that
8//!   the CLI and the HTTP server are both thin wrappers over.
9//!
10//! "API first": the CLI (`ffmpeg`/`ffprobe`) and the server expose *this* API.
11//! There is no logic in those front-ends that isn't reachable programmatically.
12
13pub use rff_codec as codec;
14pub use rff_core as core;
15pub use rff_format as format;
16
17pub mod probe;
18pub mod targets;
19pub mod transcode;
20
21use rff_codec::CodecRegistry;
22use rff_format::FormatRegistry;
23
24/// A fully-wired engine: every built-in codec and container, ready to use.
25///
26/// Construct one with [`Engine::new`] and hand it to [`transcode`] / [`probe`],
27/// or query its registries directly (e.g. to implement `ffmpeg -codecs`).
28pub struct Engine {
29    pub codecs: CodecRegistry,
30    pub formats: FormatRegistry,
31}
32
33impl Engine {
34    /// Build an engine with all built-in codecs and formats registered.
35    pub fn new() -> Engine {
36        let mut codecs = CodecRegistry::new();
37        register_builtin_codecs(&mut codecs);
38
39        let mut formats = FormatRegistry::new();
40        register_builtin_formats(&mut formats);
41
42        Engine { codecs, formats }
43    }
44}
45
46impl Default for Engine {
47    fn default() -> Self {
48        Engine::new()
49    }
50}
51
52/// Register every codec compiled into this build. New codec crates get one line
53/// here.
54fn register_builtin_codecs(codecs: &mut CodecRegistry) {
55    rff_codec_h264::register(codecs);
56    rff_codec_hevc::register(codecs);
57    rff_codec_opus::register(codecs);
58    rff_codec_avif::register(codecs);
59    rff_codec_png::register(codecs);
60    rff_codec_jpeg::register(codecs);
61    rff_codec_gif::register(codecs);
62    rff_codec_webp::register(codecs);
63    rff_codec_pcm::register(codecs);
64    rff_codec_vorbis::register(codecs);
65    rff_codec_flac::register(codecs);
66    rff_codec_jxl::register(codecs);
67    rff_codec_aac::register(codecs);
68    rff_codec_vp9::register(codecs);
69    rff_codec_av2::register(codecs);
70    rff_codec_mp3::register(codecs);
71    rff_codec_rawvideo::register(codecs);
72    // H.264 defaults to the in-house pure-Rust `rusty_h264` (registered above).
73    // The `h264-openh264` feature swaps in Cisco's C/FFI openh264 instead — a
74    // cross-check / fallback option, off by default.
75    #[cfg(feature = "h264-openh264")]
76    rff_codec_openh264::register(codecs);
77}
78
79/// Register every container format compiled into this build.
80fn register_builtin_formats(formats: &mut FormatRegistry) {
81    rff_format_avi::register(formats);
82    rff_format_avif::register(formats);
83    rff_format_png::register(formats);
84    rff_format_jpeg::register(formats);
85    rff_format_gif::register(formats);
86    rff_format_webp::register(formats);
87    rff_format_wav::register(formats);
88    rff_format_y4m::register(formats);
89    rff_format_ivf::register(formats);
90    // AV2F is EXPERIMENTAL: its four-character codes are chosen by us, not
91    // specified by AOM. Files written here are readable here and nowhere else.
92    rff_format_av2f::register(formats);
93    rff_format_ogg::register(formats);
94    rff_format_flac::register(formats);
95    rff_format_mp3::register(formats);
96    rff_format_jxl::register(formats);
97    rff_format_mp4::register(formats);
98    rff_format_mkv::register(formats);
99    rff_format_ts::register(formats);
100    rff_format_flv::register(formats);
101    rff_format_srt::register(formats);
102    rff_format_webvtt::register(formats);
103    rff_format_ass::register(formats);
104    rff_format_hls::register(formats);
105    rff_format_mjpeg::register(formats);
106    rff_format_rtp::register(formats);
107}
108
109/// The crate version, surfaced in the CLI/server banners.
110pub const VERSION: &str = env!("CARGO_PKG_VERSION");