//! Video engine: demux -> decode -> pixel convert. No UI dependencies. #![forbid(unsafe_code)] pub mod ao; pub mod auto_color; pub mod audio; pub mod caps; pub mod captionanim; pub mod clock; pub mod collect; pub mod color; pub mod colorspace; pub mod cube; pub mod looks; pub mod convert; pub mod decode; pub mod deinterlace; pub mod ivtc; pub mod demux; pub mod duck; pub mod edith; pub mod effects; pub(crate) mod extaudio; pub mod editkeys; pub mod envcfg; pub mod eq; mod adts; pub mod export; pub mod export_presets; pub mod flac_write; pub mod generate; pub mod interchange; pub mod opus_write; pub mod hw; pub mod hwproc; pub mod limiter; pub mod loudness; pub mod normalize; pub(crate) mod map; pub mod mux; pub(crate) mod mp4track; pub mod playback; pub mod project; pub mod proxy; pub mod render_cache; pub mod pulse; mod prores_out; pub mod real_library; pub(crate) mod reverse; pub mod scale; pub mod scenes; pub mod scopes; pub mod scratch; pub mod sequence; pub mod multisync; pub mod beats; pub mod silence; pub mod speech; pub mod recorder; pub mod reframe; pub mod stabilise; pub(crate) mod stretch; pub mod subtitle; #[cfg(test)] mod sweep; mod video_profile; pub mod text; pub mod titleanim; pub mod tonemap; pub mod track; pub mod transform; pub mod transitions; pub mod templates; pub mod versions; pub mod voice; pub mod tts; pub mod waveform; pub use audio::{ AacPacket, AacTrackParams, AudioChunk, AudioMeta, AudioProbe, AudioSession, StreamInfo, }; pub use clock::PlaybackClock; pub use decode::{ DecodeFailure, DecodeSession, Frame, UnsupportedStillOrientation, image_orientation, image_size, }; pub use demux::{ Codec, MediaBitrate, MediaFacts, Rotation, StreamFacts, StreamKind, UnsupportedRotation, VideoFacts, VideoMeta, probe_bitrate, probe_media, }; pub use export::ExportHandle; pub use mux::{AudioParams, Mp4Muxer, VideoParams}; pub use playback::{AngleSync, MulticamJob, MulticamPlan, ImportGate, ImportProbe, Levels, MulticamReport, MulticamSync, PlaybackSession}; pub use project::{Bin, Clip, GainKey, Project, Rate, SourceEdit, Speed, Title}; /// Whether a path names a standalone audio file -- a source with no picture, /// which belongs on the audio lane and nowhere else. Extension only, lowercased: /// the decoder is what really decides, but a front-end has to know which lane a /// dropped file may land on *before* anything is opened, and so does /// [`PlaybackSession::import`](playback::PlaybackSession::import). /// /// Exactly the containers the engine's audio path reads (`audio::AudioSession`), /// Opus included: `.opus` is an Ogg file symphonia's probe already reads and /// `ec-opus` decodes, and `.mka` is the Matroska whose sound is all it /// has. A `.dts` or a bare `.ac3` is refused by the same door that refuses a /// `.txt` -- there is no reader here that opens an elementary stream -- which is /// the honest answer. /// /// The `.mpeg` and `.mpg` spellings are on the list because an MPEG audio /// stream has no container to name it and the file is whatever a recorder /// called it: those two are the *standard's* name -- what a voice note or a /// tagged download off the web wears -- where `.mp3` is the codec's. Symphonia's /// `mp3` reader is what reads them, the same reader an `.mp3` goes through, and /// it skips the ID3v2 tag and any cover picture muxed into one. A `.mpeg`/`.mpg` that /// is really an MPEG *program stream* with a picture in it is read by the program /// stream demuxer ([`demux::is_mpegps`]) and is no audio file: those two spellings /// are the one place the bytes are looked at. (MPEG's other two layers, `.mp1`/`.mp2`, are /// deliberately absent: this build compiles the mp3 bundle without its `mp1`/ /// `mp2` features, so a layer II stream is a codec nothing here decodes, and /// admitting the spelling would be a promise the reader cannot keep.) pub fn is_audio(path: &std::path::Path) -> bool { let named = path.extension().and_then(|e| e.to_str()).is_some_and(|e| { matches!( e.to_ascii_lowercase().as_str(), "mp3" | "mpeg" | "mpg" | "wav" | "flac" | "ogg" | "oga" | "opus" | "mka" | "m4a" | "aac" | "dts" | "dtshd" | "amr" | "awb" ) }); // `.mpg`/`.mpeg` also name an MPEG program stream with a picture (a DVD's, a camcorder's), // which belongs on a video lane: the bytes decide those two spellings, when the file exists. named && !(path .extension() .and_then(|e| e.to_str()) .is_some_and(|e| e.eq_ignore_ascii_case("mpg") || e.eq_ignore_ascii_case("mpeg")) && demux::carries_picture(path)) } /// Whether a path names a still image -- a source with a picture and no sound /// and no length of its own, which belongs on a video lane and nowhere else. /// Extension only, lowercased, for [`is_audio`]'s reason: a front-end has to /// know which lane a dropped file may land on before anything is opened. /// /// Exactly the formats `image` is built with here (see `Cargo.toml`): PNG, /// JPEG and WebP. A `.gif` or a `.tif` is refused by the same door that refuses /// a `.txt`, which is the honest answer until a decoder for it is compiled in. pub fn is_image(path: &std::path::Path) -> bool { // A generator ([`generate`]) is a picture with no file behind it. generate::is_generated(path) || path.extension().and_then(|e| e.to_str()).is_some_and(|e| { matches!( e.to_ascii_lowercase().as_str(), "png" | "jpg" | "jpeg" | "webp" ) }) } /// Whether a source's file is there to read: a real file, or a generator, which has none to miss. pub fn source_present(path: &std::path::Path) -> bool { generate::is_generated(path) || path.exists() // A numbered run's spelling is not a file: it is there when its first frame is. || sequence::Run::parse(path).is_some_and(|run| run.frame(0).exists()) } /// The largest picture this engine composes onto, either way: 7680, which is /// where a per-frame buffer stops being a sane thing to allocate. /// /// That is 8K **UHD** (7680x4320), not 8K DCI (8192x4320). A DCI-width master /// -- a ProRes 4444 XQ feature, for instance -- is 8192 wide and is refused /// here by name, which it was not before the container doors asked this bound /// of a file's own header rather than only of a keystroke and a `.edith` line. /// The bound is deliberately not raised to 8192 to admit it: `is_resolution` /// gates those two doors at 7680 too, and widening the ceiling on every path /// to accommodate a container is a wider decision than a header fix should /// make. A caller that needs DCI width needs the ceiling raised deliberately, /// on all four doors at once. pub const MAX_RESOLUTION: u32 = 7680; /// Whether a project resolution is a picture at all: not zero either way, and /// not past [`MAX_RESOLUTION`]. Both doors ask -- the keystroke /// ([`PlaybackSession::set_resolution`](playback::PlaybackSession::set_resolution)) /// and the file ([`edith::load`]) -- so a hand-written `resolution` line cannot /// reach an allocation a keypress could not, which is how `4294967295` used to /// panic the open with a capacity overflow. pub fn is_resolution(width: u32, height: u32) -> bool { (1..=MAX_RESOLUTION).contains(&width) && (1..=MAX_RESOLUTION).contains(&height) } /// Boxed error; the engine has few failure modes and every one of them is fatal /// to the session, so a message is all a caller can act on. pub type Error = Box; pub type Result = std::result::Result; #[cfg(test)] mod tests { use std::path::Path; #[test] fn is_audio_admits_the_containers_the_decoder_reads() { for name in [ "song.mp3", "a.WAV", "b.flac", "c.ogg", "d.oga", "e.m4a", "f.aac", "g.opus", "h.OPUS", "i.mka", "j.MPEG", "k.mpg", "l.dts", "m.DTSHD", "n.amr", "o.awb", ] { assert!(super::is_audio(Path::new(name)), "{name}"); } // Video, projects, the elementary streams no reader here opens, and a // file with no extension at all: all of them go elsewhere. for name in [ "clip.mp4", "take.MP4", "cut.edith", "y.ac3", "notes", "mp3", ] { assert!(!super::is_audio(Path::new(name)), "{name}"); } } #[test] fn is_image_admits_the_formats_the_decoder_is_built_with() { for name in ["shot.png", "a.JPG", "b.jpeg", "c.webp"] { assert!(super::is_image(Path::new(name)), "{name}"); } // Media, projects, the still formats no decoder is compiled in for, // and a file with no extension: all of them go elsewhere. The two // predicates never both hold -- which lane a file may land on is one // answer, not two. for name in ["clip.mp4", "song.mp3", "cut.edith", "d.gif", "e.tif", "png"] { assert!(!super::is_image(Path::new(name)), "{name}"); assert!( !(super::is_image(Path::new(name)) && super::is_audio(Path::new(name))), "{name}" ); } } }