code: def wrap_with_monitor(env, video_dir):
      """Wrap environment with gym.Monitor.
  
      Video recording provided by Monitor requires
        1) both height and width of observation to be even numbers.
        2) rendering of environment
  
      Args:
        env: environment.
        video_dir: video directory.
  
      Returns:
        wrapped environment.
      """
      env = ExtendToEvenDimentions(env)
      env = RenderObservations(
          env
      )  # pylint: disable=redefined-variable-type
      env = gym.wrappers.Monitor(
          env,
          video_dir,
          force=True,
          video_callable=lambda idx: True,
          write_upon_reset=True,
      )
      return env
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import copy
  import os
  import re
  import gym
  import numpy
  import six
  from tensor2tensor.models.research.rl import get_policy
  from tensor2tensor.models.research.rl import make_simulated_env_fn_from_hparams
  from tensor2tensor.rl import rl_utils
  from tensor2tensor.rl.envs.simulated_batch_gym_env import FlatBatchEnv
  from tensor2tensor.utils import hparam
  from tensor2tensor.utils import trainer_lib
  from tensor2tensor.utils.misc_utils import camelcase_to_snakecase
  import tensorflow.compat.v1
label_desc: Use image node_id 5 for calling a global function with example usage: wrap_with_monitor(env, video_dir) and returns: env