Skip to main content

ff_sys/
lib.rs

1//! # ff-sys
2//!
3//! Low-level FFmpeg FFI bindings for Rust.
4//!
5//! This crate provides raw FFI bindings to FFmpeg libraries, generated by
6//! [bindgen](https://github.com/rust-lang/rust-bindgen). It is intended as a
7//! building block for higher-level safe wrappers.
8//!
9//! ## Safety
10//!
11//! All functions in this crate are unsafe. Higher-level safe wrappers are provided
12//! by other ff-* crates:
13//! - `ff-probe` - Media metadata extraction
14//! - `ff-decode` - Decoding and seeking
15//! - `ff-encode` - Encoding and export
16//! - `ff-filter` - Filters and effects
17
18// The hand-written wrapper modules below are held to the normal lint set plus
19// `unsafe_op_in_unsafe_fn`; only the auto-generated bindings opt out of it, inside
20// `mod raw`.
21#![deny(unsafe_op_in_unsafe_fn)]
22
23// Auto-generated bindgen output is isolated behind this module so its blanket
24// lint allow does not silence the hand-written wrapper modules. On docs.rs
25// (DOCS_RS=1) the build script emits an empty bindings.rs and sets cfg(docsrs);
26// we include the hand-written stubs instead so dependent crates compile unchanged.
27// `pub use raw::*` keeps every bindgen symbol available at the crate root, so
28// downstream `ff_sys::<name>` references are unaffected.
29mod raw {
30    #![allow(warnings)]
31    #![allow(unsafe_op_in_unsafe_fn)]
32
33    #[cfg(not(docsrs))]
34    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
35
36    #[cfg(docsrs)]
37    include!("docsrs_stubs.rs");
38}
39pub use raw::*;
40
41// Wrapper modules (real bindings only)
42#[cfg(not(docsrs))]
43pub mod avcodec;
44#[cfg(not(docsrs))]
45pub mod avformat;
46#[cfg(not(docsrs))]
47mod io_context;
48#[cfg(not(docsrs))]
49pub mod swresample;
50#[cfg(not(docsrs))]
51pub mod swscale;
52
53// Sub-modules
54#[cfg(not(docsrs))]
55mod bsf;
56#[cfg(not(docsrs))]
57mod buffersink;
58#[cfg(not(docsrs))]
59mod codec;
60#[cfg(not(docsrs))]
61mod codec_context;
62mod constants;
63mod error;
64pub mod error_codes;
65// Ungated: pure `Read`/`Write` + `Seek` bounds with no FFmpeg dependency, so the
66// docs.rs stubs can name them too.
67#[cfg(not(docsrs))]
68mod format_context;
69#[cfg(not(docsrs))]
70mod frame;
71#[cfg(not(docsrs))]
72mod hwdevice;
73mod io_traits;
74mod log_bridge;
75#[cfg(not(docsrs))]
76mod packet;
77#[cfg(not(docsrs))]
78mod resample_context;
79#[cfg(not(docsrs))]
80mod scale_context;
81mod utils;
82
83// Re-exports
84#[cfg(not(docsrs))]
85pub use bsf::BsfContext;
86#[cfg(not(docsrs))]
87pub use buffersink::{BufferSinkOutcome, buffersink_get_frame};
88#[cfg(not(docsrs))]
89pub use codec::Codec;
90#[cfg(not(docsrs))]
91pub use codec_context::{CodecContext, ReceiveOutcome};
92pub use constants::{
93    AV_NOPTS_VALUE, AVFMT_FLAG_CUSTOM_IO, AVFMT_NOFILE, AVFMT_TS_DISCONT, BUFFERSRC_FLAG_KEEP_REF,
94};
95pub use error::AvError;
96#[cfg(not(docsrs))]
97pub use format_context::{
98    ChapterRef, ChapterSpec, CodecParameters, InputFormatContext, OutputFormatContext, StreamRef,
99};
100#[cfg(not(docsrs))]
101pub use frame::Frame;
102#[cfg(not(docsrs))]
103pub use hwdevice::HwDeviceContext;
104pub use io_traits::{IoSink, IoSource};
105pub use log_bridge::{install_log_bridge, log_level, set_log_level};
106#[cfg(not(docsrs))]
107pub use packet::Packet;
108#[cfg(not(docsrs))]
109pub use resample_context::ResampleContext;
110#[cfg(not(docsrs))]
111pub use scale_context::ScaleContext;
112pub use utils::{av_error_string, ensure_initialized};
113// check_av_error! is re-exported at the crate root automatically via #[macro_export]