MCPcopy Index your code
hub / github.com/google/adk-python / generate_video

Function generate_video

contributing/samples/core/artifacts/agent.py:73–103  ·  view source on GitHub ↗

Generates a simple valid MP4 video using OpenCV. Requires opencv-python.

(filename: str)

Source from the content-addressed store, hash-verified

71
72
73def generate_video(filename: str):
74 """Generates a simple valid MP4 video using OpenCV.
75
76 Requires opencv-python.
77 """
78 try:
79 import cv2
80 import numpy as np
81 except ImportError:
82 raise ImportError(
83 "opencv-python and numpy are required to generate video. Install"
84 " them with: pip install opencv-python numpy"
85 )
86
87 width, height = 320, 240
88 fourcc = cv2.VideoWriter_fourcc(*"avc1")
89 out = cv2.VideoWriter(filename, fourcc, 20.0, (width, height))
90 if not out.isOpened():
91 raise RuntimeError(
92 "Failed to open VideoWriter. The 'avc1' codec might not be supported on"
93 " this system."
94 )
95
96 for i in range(60): # 3 seconds at 20fps
97 frame = np.zeros((height, width, 3), dtype=np.uint8)
98 # Draw a moving white square
99 x = (i * 5) % width
100 cv2.rectangle(frame, (x, 100), (x + 50, 150), (255, 255, 255), -1)
101 out.write(frame)
102
103 out.release()
104
105
106async def generate_report(

Callers 1

generate_media_artifactFunction · 0.85

Calls 2

rectangleMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected