Skip to main content

Reliable, easy, and fast video playback in Python with integrations for pygame, tkinter, pyglet, and more.

Project description

pyvidplayer2

PyPI Version PyPI Downloads Status Coverage security: bandit Python Version from PEP 621 TOML Ask DeepWiki Made with ❤️

Comprehensive video playback library for Python.

This library is under active development. If you encounter a bug or a video that cannot be played, please open an issues page.

Features

  • Easy integration: Add a video to an existing app with just 4 lines of code
  • Lightweight: Almost every dependency is optional
  • Feature-rich: Seamless loops, custom playback speed, reverse playback, parallel playback, and more
  • Full audio support: Adjust audio track, output device, volume, and more
  • Full subtitle support: Parse subtitles from files or embedded subtitle tracks
  • Play any format: Supports almost every codec and container, VFR videos, even GIFs
  • YouTube integration: Stream videos and subtitles directly from YouTube
  • Low-level control: Frame-by-frame iteration and inspection
  • High compatibility: Integrates with 7 graphics libraries (some features limited to Pygame)
  • Extra features: Built-in video player GUI, post-processing effects, and webcam features

Installation

pip install pyvidplayer2

In addition, FFmpeg and FFprobe must be downloaded and accessible via PATH. Windows users can go to the official website to download FFmpeg (includes FFprobe). Add the bin folder location to the PATH environment variable. There's plenty of tutorials online for this. Linux and MacOS users can use their package manager of choice.

Legacy Installations

Versions prior to v0.9.31 have a PyAudio dependency. To build the wheel for it, some system packages must be present. Install them with your package manager before running pip install pyvidplayer2.

  • Ubuntu/Debian: sudo apt install python3-dev libjack-jackd2-dev portaudio19-dev
  • Fedora/RHEL: sudo dnf install python3-devel portaudio-devel
  • MacOS: brew install portaudio

Dependencies

numpy
FFmpeg and FFprobe (binaries, not Python packages)

Still requires one graphics library and one audio library of your choice.

Optional Packages

opencv_python       (efficiency improvements and more features, comes installed)
pygame/pygame-ce    (graphics and audio library)
sounddevice         (better audio library, comes installed)
pysubs2             (for subtitles)
yt_dlp[default]     (for streaming Youtube videos)
decord              (for videos in bytes, best option)
imageio[pyav]       (for videos in bytes)
pyglet              (graphics library)
PySide6             (graphics library)
PyQt6               (graphics library)
tkinter             (graphics library, installed as a sys package or with Python installer, not pip)
raylib              (graphics library)
wxPython            (graphics library)

Use pip install pyvidplayer2[all] to install all packages required for running the unit tests. Not required or recommended for regular users.

Quickstart

Refer to the examples folder for more basic examples.

Pygame Integration

Refer to the examples folder for integrations with other graphics libraries.

import pygame
from pyvidplayer2 import Video


# Create video object

vid = Video("video.mp4")

win = pygame.display.set_mode(vid.current_size)
pygame.display.set_caption(vid.name)


while vid.active:
    key = None
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            vid.stop()
        elif event.type == pygame.KEYDOWN:
            key = pygame.key.name(event.key)

    if key == "r":
        vid.restart()           # Rewind video to beginning
    elif key == "p":
        vid.toggle_pause()      # Pause/play video
    elif key == "m":
        vid.toggle_mute()       # Mute/unmute video
    elif key == "right":
        vid.seek(15)            # Skip 15 seconds in video
    elif key == "left":
        vid.seek(-15)           # Rewind 15 seconds in video
    elif key == "up":
        vid.set_volume(1.0)     # Max volume
    elif key == "down":
        vid.set_volume(0.0)     # Min volume

    # Only draw new frames, and only update the screen if something is drawn

    if vid.draw(win, (0, 0), force_draw=False):
        pygame.display.update()

    pygame.time.wait(16)


# Close video when done

vid.close()
pygame.quit()

Documentation

To get started quickly, you can browse the many code examples. For more detailed information, read the documentation. If you prefer natural language, try asking DeepWiki. If you still have questions, open an issues page.

Known Bugs

For a list of known bugs, refer to this page. If you see an issue not listed, please open a new issue.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvidplayer2-0.9.35.tar.gz (65.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvidplayer2-0.9.35-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file pyvidplayer2-0.9.35.tar.gz.

File metadata

  • Download URL: pyvidplayer2-0.9.35.tar.gz
  • Upload date:
  • Size: 65.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyvidplayer2-0.9.35.tar.gz
Algorithm Hash digest
SHA256 7ee169e5c49b2ea6adf103f519492dcc23f7b6dea0c2f2763ebca7d2db21b40a
MD5 6e70c7d5cb293ddaf75bab2fbb102ce2
BLAKE2b-256 91385fbcfd22eefd5c67b03c6f543c3ab39ddb1102a757c4972ebd774292e128

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvidplayer2-0.9.35.tar.gz:

Publisher: release.yml on anrayliu/pyvidplayer2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvidplayer2-0.9.35-py3-none-any.whl.

File metadata

  • Download URL: pyvidplayer2-0.9.35-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyvidplayer2-0.9.35-py3-none-any.whl
Algorithm Hash digest
SHA256 dc1adb7581d456313057842ea790ab495a2b1e2e5104c3ea6fb9806733fb260e
MD5 8c6e557181ecb4bf55a62f4d147cd92d
BLAKE2b-256 817e95e93bb1d9f3194ccf2f51c9998be063b0940f050c11ed6f92efdaf6e012

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvidplayer2-0.9.35-py3-none-any.whl:

Publisher: release.yml on anrayliu/pyvidplayer2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page