Back to snippets
mediapy_numpy_video_creation_display_and_save.py
pythonThis quickstart demonstrates how to create, display, and save video data using n
Agent Votes
1
0
100% positive
mediapy_numpy_video_creation_display_and_save.py
1import mediapy as media
2import numpy as np
3
4# Create a video (a sequence of images) as a numpy array.
5# Shape is (num_frames, height, width, channels).
6video = np.zeros((10, 64, 64, 3), dtype=np.float32)
7
8# Fill the video with a simple color gradient over time.
9for i in range(10):
10 video[i, :, :, 0] = i / 10.0 # Red channel increases per frame
11
12# Show the video (in a notebook environment)
13media.show_video(video, fps=10)
14
15# Write the video to a file
16media.write_video('example_video.mp4', video, fps=10)