MCPcopy Index your code
hub / github.com/OpenBMB/ChatDev / render_manim

Function render_manim

functions/function_calling/video.py:14–58  ·  view source on GitHub ↗
(
    script_path: str,
    quality: str = "h",
    preview: bool = True,
)

Source from the content-addressed store, hash-verified

12 return [node.name for node in ast.walk(tree) if isinstance(node, ast.ClassDef)]
13
14def render_manim(
15 script_path: str,
16 quality: str = "h",
17 preview: bool = True,
18) -> Path:
19 output_dir = Path.cwd() / "media"
20 print("Clearing media folder:", output_dir)
21 shutil.rmtree(output_dir, ignore_errors=True)
22 script_path = Path(script_path).resolve()
23 if not script_path.exists():
24 raise FileNotFoundError(script_path, " does not exist.")
25 scene_name = _get_class_names(str(script_path))[0]
26 cmd = [
27 sys.executable, "-m", "manim",
28 f"-pq{quality}",
29 ]
30
31 if preview:
32 cmd.insert(3, "-p")
33
34 cmd.extend([str(script_path), scene_name])
35
36 print("Running:", " ".join(cmd))
37 try:
38 subprocess.run(cmd, check=True, capture_output=True, text=True)
39 except subprocess.CalledProcessError as e:
40 print("Manim rendering failed:")
41 print("stdout:", e.stdout)
42 print("stderr:", e.stderr)
43 error_info = f"Error rendering {scene_name} from {script_path}: {e.stderr}"
44 # shutil.rmtree(output_dir, ignore_errors=True)
45 raise RuntimeError(error_info)
46
47 # Find valid mp4 files where no parent directory contains a partial_movie_files folder
48 video_file = None
49 for mp4_file in (Path.cwd() / "media" / "videos").parent.rglob("*.mp4"):
50 if mp4_file.name == f"{scene_name}.mp4":
51 video_file = mp4_file
52 break
53
54 target_path = script_path.parent / video_file.name
55 print(f"Copying video to {target_path}")
56 shutil.copy2(video_file, target_path)
57 shutil.rmtree(output_dir, ignore_errors=True)
58 return target_path
59
60def concat_videos(video_paths: list[Path]) -> Path:
61 if not video_paths:

Callers

nothing calls this directly

Calls 3

_get_class_namesFunction · 0.85
resolveMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected