# Saving Gym Environment Video with RLlib

**URL:** <https://discuss.ray.io/t/saving-gym-environment-video-with-rllib/396>\
**Category:** RLlib\
**Created:** [January 7, 2021, 5:00am UTC](https://discuss.ray.io/t/saving-gym-environment-video-with-rllib/396 "2021-01-07T05:00:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgonik](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/jgonik/32/1115_2.png) [@jgonik](https://discuss.ray.io/u/jgonik)\
**Post date:** [January 7, 2021, 5:00am UTC](https://discuss.ray.io/t/saving-gym-environment-video-with-rllib/396/1 "2021-01-07T05:00:58Z")

</div>

Hi! I’m trying to save videos of the training process on the Gym Car Racing environment using the Python API for RLlib. Here’s my code:

```auto
import gym
import ray
from gym.wrappers import ResizeObservation
from ray.tune.registry import register_env

from ray import tune
import ray.rllib.agents.ppo as ppo

def env_creator(env_config):
    env = gym.make('CarRacing-v0', **env_config)
    return ResizeObservation(env, (84, 84))

ray.shutdown()
ray.init(ignore_reinit_error=True)

register_env('CarRacingResized', env_creator)

ENV = 'CarRacingResized'
CHECKPOINT = './ray/racing'
config = ppo.DEFAULT_CONFIG.copy()
config['log_level'] = 'INFO'
config['framework'] = 'torch'
config['monitor'] = True

agent = ppo.PPOTrainer(config, env=ENV)

N_ITER = 30
s = '{:3d} reward {:6.2f}/{:6.2f}/{:6.2f} len {:6.2f} saved {}'

for n in range(N_ITER):
  result = agent.train()
  file_name = agent.save(CHECKPOINT)

  print(s.format(
    n + 1,
    result['episode_reward_min'],
    result['episode_reward_mean'],
    result['episode_reward_max'],
    result['episode_len_mean'],
    file_name
   ))

```

However, the videos that get saved in the `~/ray_results` directory are just a black screen for a split second. I’ve also tried saving videos of the CartPole environment and I ran into the same issue. I thought that the `config['monitor']` flag was all I needed to save video. Am I doing something incorrectly?

Thank you!
