OpenAI gym Monitor wrapper only generates JSON data instead of video recordings

I’m working on a reinforcement learning project using gym’s FrozenLake-v0 environment and trying to capture video recordings of my agent’s performance. I’m using the Monitor wrapper to record the episodes, but I’m running into an issue where only JSON files are being created in my output folder instead of actual video files.

Here’s the code I’m using:

import gym
import time

environment = gym.make('CartPole-v1')
environment = gym.wrappers.Monitor(environment, './videos/', force=True)
environment.seed(42)

best_values = compute_value_iteration(environment)
start_time = time.time()
best_policy = generate_policy(best_values)
final_score = test_policy(environment, best_policy)
end_time = time.time()

environment.close()
print('Final score: %.2f  Execution time: %4.4f seconds' % (final_score, end_time-start_time))

When I check the videos directory, I only see JSON metadata files but no MP4 or AVI video files. I expected the Monitor wrapper to automatically generate video recordings of the episodes. Has anyone encountered this problem before? What additional steps do I need to take to get actual video files instead of just the JSON logs?

i had the same issue! make sure you have ffmpeg installed, the Monitor wrapper needs it to save the videos. otherwise, it’ll just give you json files. try installing ffmpeg, that should solve it!

The Monitor wrapper doesn’t record every episode - it only captures videos for specific episodes like 1, 8, 27, 64, etc. The gaps between recordings get bigger over time. If your training runs are short and don’t hit these episode numbers, you won’t get any video files. Want to record every episode? Set the video_callable parameter to lambda episode_id: True when you create the Monitor wrapper. Also double-check that your test_policy function is actually stepping through episodes - if it’s not running properly, there’s nothing to record.

This is exactly why I ditched the Monitor wrapper and automated my whole RL pipeline.

Those JSON files show your episodes are running but video encoding’s broken. You need ffmpeg installed, and the default recording schedule is still wonky even then.

I built a workflow that grabs episode data, converts it to proper video format, and dumps everything in organized folders. No more wondering if Monitor will actually work today.

The workflow handles video encoding separately from gym, so I get the same results every time. It also uploads videos to cloud storage, sends me notifications when training’s done, and generates performance charts automatically.

Set it up once and every RL experiment gets documented without me touching anything. Beats debugging gym wrapper problems every few weeks.

You can build something similar at https://latenode.com

Check your environment variables for video recording. The Monitor wrapper needs proper system PATH configuration to find video encoding libraries. I had the same issue when my system couldn’t access the required codecs, even though ffmpeg was installed correctly. Gym version compatibility is another common problem. Older versions had spotty video recording, especially with certain environments. If you’re running an outdated version, try upgrading. Make sure your test_policy function actually calls environment.step() and environment.render(). The Monitor wrapper only creates videos when episodes finish through the normal gym interface. If your policy testing skips the standard episode flow, you’ll just get JSON metadata without any visual content.