{"id":4629,"library":"mediapy","title":"mediapy","description":"mediapy is a Python library designed to simplify reading, writing, and displaying images and videos, especially within IPython/Jupyter notebooks. Developed by Google LLC, it is currently on version 1.2.6 and receives updates periodically.","status":"active","version":"1.2.6","language":"en","source_language":"en","source_url":"https://github.com/google/mediapy","tags":["image","video","jupyter","notebook","display","media","io"],"install":[{"cmd":"pip install mediapy","lang":"bash","label":"Install mediapy"}],"dependencies":[{"reason":"Fundamental for image and video data handling as NumPy arrays.","package":"numpy","optional":false},{"reason":"Used for image processing tasks.","package":"pillow","optional":false},{"reason":"External command-line tool required for all video input/output operations. Must be installed separately and accessible in system PATH.","package":"ffmpeg","optional":false}],"imports":[{"symbol":"mediapy","correct":"import mediapy as media"}],"quickstart":{"code":"import mediapy as media\nimport numpy as np\nimport shutil\nimport os\n\n# --- Image Example ---\nimage_url = 'https://github.com/hhoppe/data/raw/main/image.png'\nprint(f\"Reading image from: {image_url}\")\nimage = media.read_image(image_url)\nprint(f\"Image shape: {image.shape}, dtype: {image.dtype}\")\nmedia.show_image(image, title='Remote Image')\n\n# Example of creating and saving an image\ncheckerboard = np.kron([[0, 1] * 16, [1, 0] * 16] * 16, np.ones((4, 4)))\noutput_image_path = '/tmp/checkerboard.png'\nmedia.write_image(output_image_path, checkerboard)\nprint(f\"\\nCheckerboard image written to {output_image_path}\")\n\n# --- Video Example (requires ffmpeg) ---\nif shutil.which('ffmpeg'):\n    video_url = 'https://github.com/hhoppe/data/raw/main/video.mp4'\n    print(f\"\\nReading video from: {video_url}\")\n    video = media.read_video(video_url)\n    print(f\"Video shape: {video.shape}, dtype: {video.dtype}\")\n    if hasattr(video, 'metadata') and hasattr(video.metadata, 'fps'):\n        print(f\"Video framerate: {video.metadata.fps} fps\")\n        media.show_video(video, title='Remote Video', fps=video.metadata.fps)\n    else:\n        media.show_video(video, title='Remote Video - FPS unknown')\nelse:\n    print(\"\\nFFmpeg is not installed or not in PATH. Skipping video example.\")\n    print(\"Please install ffmpeg (e.g., 'brew install ffmpeg' on macOS, 'apt install ffmpeg' on Debian/Ubuntu) for video functionality.\")\n","lang":"python","description":"This quickstart demonstrates how to read and display both local/remote images and videos. For video functionality, ensure that the `ffmpeg` command-line tool is installed and accessible in your system's PATH. An example of writing an image to a file is also included."},"warnings":[{"fix":"Install `ffmpeg` for your operating system (e.g., `brew install ffmpeg` on macOS, `apt install ffmpeg` on Debian/Ubuntu, or download from ffmpeg.org).","message":"Video input/output operations (e.g., `read_video`, `write_video`, `show_video`) are dependent on the external `ffmpeg` command-line tool. It must be installed on your system and accessible in the system's PATH, otherwise a `RuntimeError` will be raised.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `fps=video.metadata.fps` is passed to `media.show_video()` calls, as shown in the quickstart example.","message":"When displaying videos with `media.show_video` after reading them with `media.read_video`, the framerate might not always be automatically detected or correctly applied. For accurate playback speed, it's recommended to explicitly pass the `fps` argument to `show_video` using `video.metadata.fps`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"This issue was quickly addressed in subsequent releases. Users on Python 3.8 or later should use version 1.2.2 or higher (current version 1.2.6 is compatible with Python >=3.8).","message":"Version 1.2.1 introduced an incompatibility with Python 3.8 due to the use of `os.PathLike[str]`, which was not subscriptable in Python 3.8 at the time. This caused `TypeError: 'ABCMeta' object is not subscriptable`.","severity":"breaking","affected_versions":"1.2.1"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}