Skip to content
FastVideo
Esc
↑↓navigate↵open⌘Jpreview
On this page

paths

Filesystem helpers shared by eval scripts.

Provides the prompt-sanitization, default filename convention, and (row, video_path) → eval-kwargs builder. Free functions, not a class — :class:fastvideo.eval.Evaluator is the only stateful object in the eval surface; loops live in user scripts.

fastvideo.eval.io.paths.sanitize_prompt

sanitize_prompt(prompt: str, max_len: int = 100) -> str

Prompt → safe filename stem.

Source
def sanitize_prompt(prompt: str, max_len: int = 100) -> str:
    """Prompt → safe filename stem."""
    s = _INVALID_CHARS.sub("", prompt[:max_len]).strip().strip(".")
    return re.sub(r"\s+", " ", s) or "output"

fastvideo.eval.io.paths.default_filename

default_filename(row: dict, idx: int, ext: str = '.mp4') -> str

<sanitized-prompt>-<idx>.mp4 — VBench-style.

Source
def default_filename(row: dict, idx: int, ext: str = ".mp4") -> str:
    """``<sanitized-prompt>-<idx>.mp4`` — VBench-style."""
    return f"{sanitize_prompt(row['prompt'])}-{idx}{ext}"

fastvideo.eval.io.paths.glob_videos

glob_videos(videos_dir: Path, row: dict, ext: str = '.mp4') -> list[Path]

Find every generated video for row, sorted by trailing -<idx>.

Source
def glob_videos(videos_dir: Path, row: dict, ext: str = ".mp4") -> list[Path]:
    """Find every generated video for *row*, sorted by trailing ``-<idx>``."""
    pattern = f"{sanitize_prompt(row['prompt'])}-*{ext}"
    files = list(videos_dir.glob(pattern))
def _idx(p: Path) -&gt; int:
    try:
        return int(p.stem.rsplit(&quot;-&quot;, 1)&#91;1&#93;)
    except (IndexError, ValueError):
        return -1

return sorted(files, key=_idx)</code></pre></details>

fastvideo.eval.io.paths.build_eval_kwargs

build_eval_kwargs(row: dict, video_path: Path, *, fps: float = 24.0) -> dict[str, Any]

Build evaluator kwargs from a sample row + a video on disk.

Loads the video as (T,C,H,W) and adds the leading batch dim. Forwards prompt (as scalar text_prompt) and auxiliary_info (as scalar dict) when present on the row — matches the one-sample-per-call contract that the evaluator and every metric assume.

Source
def build_eval_kwargs(row: dict, video_path: Path, *, fps: float = 24.0) -> dict[str, Any]:
    """Build evaluator kwargs from a sample row + a video on disk.
Loads the video as ``(T,C,H,W)`` and adds the leading batch dim.
Forwards ``prompt`` (as scalar ``text_prompt``) and
``auxiliary_info`` (as scalar dict) when present on the row —
matches the one-sample-per-call contract that the evaluator and
every metric assume.
&quot;&quot;&quot;
from fastvideo.eval.io.video import load_video

video = load_video(str(video_path))  # (T, C, H, W) in &#91;0, 1&#93;
kwargs: dict&#91;str, Any&#93; = &#123;
    &quot;video&quot;: video.unsqueeze(0),  # (1, T, C, H, W)
    &quot;fps&quot;: fps,
&#125;
if &quot;prompt&quot; in row:
    kwargs&#91;&quot;text_prompt&quot;&#93; = row&#91;&quot;prompt&quot;&#93;
aux = row.get(&quot;auxiliary_info&quot;)
if aux:
    kwargs&#91;&quot;auxiliary_info&quot;&#93; = aux
return kwargs</code></pre></details>

Was this page helpful?