Module media

Source
Expand description

Media decoding: a small trait layer over two backends.

  • mf — Windows Media Foundation (native software decode, no external deps, instant seeks). Primary.
  • ffpipe — ffmpeg.exe / ffprobe.exe child processes. Universal fallback, images, probing, export. Everything produces top-down RGBA8 frames and interleaved stereo f32 audio at SAMPLE_RATE.

Modules§

ffpipe
ffmpeg.exe / ffprobe.exe child-process backend. Universal fallback decoder, image loader, prober, and the process launcher used by export.
mf
Windows Media Foundation backend (IMFSourceReader). Native software decode, no external deps, instant seeks.
proxy
Proxy media: background all-intra low-res transcodes of imported video, played instead of the originals in the preview. Every proxy frame is a keyframe (-g 1), so seeks, reverse scrubs and clip-boundary cold opens decode without reference chains — the reason big NLEs feel instant. Proxies live in the cache dir, named by a hash of (source path, mtime, height): a re-exported source gets a fresh proxy automatically and stale files are just never referenced again. Export and full-quality one-shot renders never see proxies (their DecoderPools carry no map).
thumbs
Thumbnail cache for timeline filmstrips and library previews. Non-blocking: get/texture return immediately; misses are queued to ONE worker thread (newest request first, so scrubbing/zooming stays responsive) that owns a DecoderPool (backend from settings) and decodes h-pixel-tall RGBA thumbnails (aspect kept; images ignore t; Sequence clips are not handled here — the timeline draws a label). Results are kept in an LRU bounded by both entry count (≤512) and decoded bytes (≤48 MB) and uploaded lazily as egui textures (texture) so panels can paint them directly. ctx.request_repaint() when a thumbnail lands. Key = (path, t rounded to 0.5 s buckets, h rounded up to 16 px); clear() forgets everything (e.g. after save-over-original).
waveform
Audio waveform peaks per (file, audio stream): computed once on a background thread (decoding the whole stream through an AudioSource), cached in memory and on disk under Settings::cache_dir() (key = hash of path + file size + mtime + stream). PEAKS_PER_SEC buckets of mono (min, max).
ytdlp
URL import: download media from a link with yt-dlp.exe, the same child-process pattern ffpipe.rs uses for ffmpeg. Entirely optional — exe() returns None when yt-dlp is not installed and the Library then hides its “Import URL…” button.

Structs§

DecoderPool
Lazily opened decoders, one per (path) / (path, audio stream). Failed opens are remembered (None) so a missing file doesn’t re-spawn work every frame.
Frame
Top-down RGBA8 image. rgba.len() == width*height*4.

Enums§

Backend

Constants§

CHANNELS
POOL_AUDIOS 🔒
POOL_VIDEOS 🔒
Live decoders kept per pool (LRU past this). Failed opens (None) are cheap and never counted.
SAMPLE_RATE

Traits§

AudioSource
VideoSource

Functions§

ext
Lower-case file extension (“” when none).
is_image_path
open_audio
open_video
probe
Probe a media file into an Asset (id = 0). ffprobe gives the richest stream metadata, so it is preferred when present; Media Foundation otherwise.