Source code for manim.utils.commands

from __future__ import annotations

import json
from pathlib import Path
from subprocess import run
from typing import Generator

__all__ = [

[docs]def capture(command, cwd=None, command_input=None): p = run(command, cwd=cwd, input=command_input, capture_output=True, text=True) out, err = p.stdout, p.stderr return out, err, p.returncode
[docs]def get_video_metadata(path_to_video: str) -> dict[str]: command = [ "ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height,nb_frames,duration,avg_frame_rate,codec_name", "-print_format", "json", str(path_to_video), ] config, err, exitcode = capture(command) assert exitcode == 0, f"FFprobe error: {err}" return json.loads(config)["streams"][0]
[docs]def get_dir_layout(dirpath: Path) -> Generator[str, None, None]: """Get list of paths relative to dirpath of all files in dir and subdirs recursively.""" for p in dirpath.iterdir(): if p.is_dir(): yield from get_dir_layout(p) continue yield str(p.relative_to(dirpath))