fframes renders videos from Rust code. A video is a type that implements [Video]. It declares
the size, frame rate and duration once and returns an SVG tree ([Svgr]) for every frame from
the [svgr!] macro. The renderer rasterises the frames on all cores, mixes the audio and
encodes the result with FFmpeg.
Pipeline
- [
Video::duration], [Video::define_scenes] and [Video::audio] are resolved into a frame timeline once per render. Scenes ([Scene], [Scenes], [Overlap]) are placed back to back, audio tracks ([AudioMap], [AudioTrack]) are placed at their sample position. - For every frame the renderer builds a [
Frame] (index, time, scene offset) and a [FFramesContext] (media lookups, scene info, video size) and calls [Video::render_frame]. Frames are rendered concurrently, so the method must be pure: read precomputed data fromself, no I/O, no panics. - The returned [
Svgr] becomes ausvgr::Tree. With thecompile-time-svgtreefeature the macro emits the tree at compile time and every subtree without{}interpolation carries a static hash, which lets the backends cache its rasterisation across frames. Without the feature the markup is a string parsed per frame. - A rendering backend ([
FFramesRenderBackend]) rasterises the tree. The built-in [cpu::CpuRenderingBackend] renders one video segment per thread with tiny-skia. The Skia backend in thefframes_skia_renderercrate walks the tree on the GPU and also executes [Shader] layers. - Segments are encoded through FFmpeg ([
EncoderOptions]), concatenated, and muxed with the audio mix ([AudioMixOptions]: summing, ducking, fades, master limiter).
Minimal video
use ;
// Every file in the folder becomes a field; fonts are registered by family name.
include_media_dir!
Without the cli feature call [render] with the output path, a backend and [RenderOptions],
or render single frames through [Previewer].
Feature flags
cpu_renderer(default): the tiny-skia based [cpu::CpuRenderingBackend] and the encoding pipeline. Disable it for awasm32build.cli: the [cli] module and itsclapdependency.compile-time-svgtree: [svgr!] builds the SVG tree at compile time and hashes static subtrees. Required by the Skia backend and by [Shader].exif: EXIF orientation of loaded images.- Codecs
h264,h265,aac,mp3lame,opus,vpx: compile the library into the static FFmpeg build. Some of them needlibav-agree-gpl,libav-agree-nonfreeorlibav-agree-version3, which state that you accept the corresponding FFmpeg license terms. - Hardware acceleration
videotoolbox,audiotoolbox,vaapi,nvidia,qsv,vulkan,mediacodec: enable the platform encoders and decoders in FFmpeg.
FFmpeg
Decoding, encoding and muxing use the FFmpeg libraries through ffmpeg-sys-next, re-exported
as [ffmpeg_sys_fframes]. On Linux and macOS FFmpeg is compiled from source during
cargo build and linked statically, so the toolchain listed in the repository README (nasm,
yasm, clang, the codec dev packages) must be installed. On Windows a prebuilt FFmpeg 9 is
linked through FFMPEG_DIR or vcpkg and the codec features are not available.