Skip to main content

Gym Video Streamer

A Video Streaming Wrapper for OpenAI's Gym Environments

Now you can Live Stream the Agent's learning behavior to Twitch/YouTube from Google Colab while training these Agents.

colab link

What’s In This Document

Installation

!pip install gym-video-streamer

And if you already have gym-video-streamer then upgrade it by this command.

!pip install --upgrade gym-video-streamer

Imports and Usage

import gym
from gym_video_streamer import SetupVirtualDisplay
from gym_video_streamer import VideoStreamer  # Streaming Wrapper
  • Now Setup the Virtual Display (only required for Google Colab):

    SetupVirtualDisplay()
    
  • Define your live stream information:

    # stream_info dictionary should be in this format only
    stream_info = {
        "URL": "rtmp://live.twitch.tv/app/", # example of Twitch URL
        "secret": "--- secret here ---"
    }
    
  • Initialize the gym env and pass it to the custom wrapper:

    # ---- {For Classic-control gym envs} ----
    env = VideoStreamer(gym.make("CartPole-v1"), stream_info)
    

    *If you don't pass stream_info then it will simply store the video locally in the videos directory.

  • Test the setup (running 100 episodes for testing):

    try:
        observation = env.reset()
        i = 0
        while True:
            if i == 100:
                break
    
            env.render()  # important to call render method on env
            action = env.action_space.sample()
            observation, reward, done, info = env.step(action)
    
            if done:
                env.reset()
                i += 1
    except Exception as e:
        print(e)
    finally:
        env.close()
    

Setup for different type of Gym Envs

  • Classic control Gym Envs: As we have seen in the above example this type of works without any extra installation/setup.

  • Box2D Gym Envs: For this type of envs you need to install the following packages:

    !pip install box2d box2d-py
    
  • Atari Gym Envs: Using this type of envs on Google Colab you, need some extra setup to make them working. When I tried, it gave me the following error Exception: ROM is missing for breakout, see https://github.com/openai/atari-py#roms for instructions. So if you know how to setup this env on Colab then do let me know ✌🏻.

  • MuJoCo & Robotics Gym Envs: Now for this type of envs, you need to setup the MuJoCo on Colab. And again I haven't done this but I found a resource that will help you Setup Mujoco-py on Linux.

License

Licensed under the MIT License.

Metadata

Release files for gym-video-streamer 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gym-video-streamer 1.0
File Size Uploaded Provenance
gym-video-streamer-1.0.tar.gz 7.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gym-video-streamer 1.0
File Interpreter ABI Platform
gym_video_streamer-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.6 kB

Release files / gym-video-streamer-1.0.tar.gz

Download URL gym-video-streamer-1.0.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d4b461cc9e0a993f4454c2250836a3b8656fad83c3568c066adf8d348c24c735
BLAKE2b-256 checksum
How to use checksums
4c938587b0992a99a4fbab7c4cf00731b426a94930a0c7de9e3d499bfdfa704b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.1

Release files / gym_video_streamer-1.0-py3-none-any.whl

Download URL gym_video_streamer-1.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca8aa01e52860d5a90b6e3ac181a0b98b14f1505bd660066ab3de333650b6c1d
BLAKE2b-256 checksum
How to use checksums
05a9bdf9a8d938e11ea73f2fb2200f3d6285c4f44512dda7ede013ca3e0f4979
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.1

Security for gym-video-streamer 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page