def _vis(generate_video=False):
    """ This function visualize and generate the video for this environment.

    Args:
        generate_video: Whether to generate the videos, in both the top-down view and the third-person view.

    Returns:
        None
    """
    FPS = 60

    env = MultiAgentRacingEnv(dict(
        use_render=generate_video,
        window_size=(1600, 1200),
        num_agents=12,
        # debug=True
    ))
    o, _ = env.reset()

    # env.engine.force_fps.disable()

    total_r = 0
    ep_s = 0
    video_bev = []
    video_interface = []

    try:
        for i in range(1, 100000):
            o, r, tm, tc, info = env.step({k: [-0.0, 1] for k in env.agents.keys()})
            for r_ in r.values():
                total_r += r_
            ep_s += 1

            if generate_video:
                import pygame
                img_interface = env.render(mode="rgb_array")
                img_bev = env.render(
                    mode="topdown",
                    show_agent_name=False,
                    target_vehicle_heading_up=False,
                    draw_target_vehicle_trajectory=False,
                    film_size=(3000, 3000),
                    screen_size=(3000, 3000),
                    crash_vehicle_done=False,
                )
                img_bev = pygame.surfarray.array3d(img_bev)
                img_bev = img_bev.swapaxes(0, 1)
                img_bev = img_bev[::-1]
                video_bev.append(img_bev)
                video_interface.append(img_interface)

            if tm["__all__"]:
                print(
                    f"Finish! Current step {i}. Group Reward: {total_r}. Average reward: {total_r / env.agent_manager.next_agent_count}"
                )
                total_r = 0
                print("Reset")
                # env.reset()
                break
    finally:
        env.close()

    if generate_video:
        import datetime
        import os
        import mediapy

        folder_name = "marl_racing_video_{}".format(datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
        os.makedirs(folder_name, exist_ok=True)

        video_base_name = f"{folder_name}/video"
        video_name_bev = video_base_name + "_bev.mp4"
        print("BEV video should be saved at: ", video_name_bev)
        mediapy.write_video(video_name_bev, video_bev, fps=FPS)

        video_name_interface = video_base_name + "_interface.mp4"
        print("Interface video should be saved at: ", video_name_interface)
        mediapy.write_video(video_name_interface, video_interface, fps=FPS)
 This function visualize and generate the video for this environment.

    Args:
        generate_video: Whether to generate the videos, in both the top-down view and the third-person view.

    Returns:
        None
    
metadrive/envs/marl_envs/marl_racing_env.py