Skip to main content

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

Project description

logo

PyPI Version PyPI Downloads Status Coverage Python Version Ask DeepWiki Made with ❤️

Striving to be the most comprehensive video playback library for Python.

Note that 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 to implement (4 lines of code)
  • Only essential dependencies are numpy, FFmpeg + FFprobe
  • Fast and efficient
  • No audio/video sync issues
  • Unlocked frame rate
  • Nvidia hardware acceleration (AMD coming later)
  • Supports GIFs!
  • Supports almost any video codec and container
  • Play variable frame rate videos (VFR)
  • Adjust playback speed
  • Reverse playback
  • Subtitle support (.srt, .ass, etc)
  • Play multiple videos in parallel
  • Add multiple subtitles to a video
  • Built in GUI and queue system
  • Draw videos using Pygame, PygameCE, Pyglet, Tkinter, PySide6, PyQT6, Raylib, or wxPython
  • Post process effects
  • Webcam feed
  • Stream videos from Youtube
  • Grab subtitles from Youtube, including automatic generation and translation
  • Play videos as byte objects
  • Specify output devices
  • Frame-by-frame iteration
  • Specify different audio tracks
  • Seamless video looping

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)

Optional Packages

At least one graphics library and one audio library is required.

opencv_python   (efficiency improvements and more features, comes installed)
pygame-ce       (graphics and audio library, comes installed)
sounddevice     (better audio library, comes installed)
pysubs2         (for subtitles, comes installed)
yt_dlp          (for streaming Youtube videos)
decord          (for videos in bytes, best option)
imageio         (for videos in bytes)
av              (required for imageio)
pyglet          (graphics library)
PySide6         (graphics library)
PyQt6           (graphics library)
tkinter         (graphics library, installed as a system 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.

Super Quick Demo

from pyvidplayer2 import Video
Video("video.mp4").preview()

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. Finally, if you still have questions, open an issues page or email me at anrayliu@gmail.com. I'm more than happy to answer!

Known Bugs

For a list of known bugs, refer to this page. If you see an issue not listed, feel free to 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.31.tar.gz (56.3 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.31-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyvidplayer2-0.9.31.tar.gz
Algorithm Hash digest
SHA256 25cacca78b62821339e5dc70defa6f7bb07365b5003497c3bf9c76b313361bba
MD5 a7a0e4d2273040374c45ff14ac53c183
BLAKE2b-256 98b67846035e2fb92e541635cf7c5b8d25da146bbf5d8f2defc95549e9946da4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvidplayer2-0.9.31.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.31-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pyvidplayer2-0.9.31-py3-none-any.whl
Algorithm Hash digest
SHA256 9a407569af635bcb6315323db0eeaa9fd7fa32e46584633a61f35b8e2b07b275
MD5 c0db538fc30926e36fe68ea912bfe529
BLAKE2b-256 9212a6288baf8ab7aab56983d6c5e639eaa4b2d9a29b413e159a3c245c5415ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvidplayer2-0.9.31-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