Created
January 21, 2022 21:18
-
-
Save skim0119/999d5c7608ebf6961073be2c3b9bee44 to your computer and use it in GitHub Desktop.
Export video of gym episode using moviepy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import gym | |
| import gym_softrobot | |
| from moviepy.editor import VideoClip | |
| def main(): | |
| fps = 30 | |
| env = gym.make('OctoFlat-v0', recording_fps=fps) | |
| # env is created, now we can use it: | |
| observation = env.reset() | |
| def make_frame(step): | |
| frame = env.render() | |
| action = env.action_space.sample() | |
| observation, reward, done, info = env.step(action) | |
| print(f"{step=:2}| {reward=}, {done=}") | |
| if done: | |
| return np.zeros_like(frame) | |
| return frame | |
| clip = VideoClip(make_frame, duration=2) | |
| clip.write_videofile("save.mp4", fps=fps) | |
| if __name__=="__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment