pip install pygamevideo
or just copy-paste pygamevideo.py to your working directory.
import pygame
from pygamevideo import Video
pygame.init()
window = pygame.display.set_mode(...)
# Load the video from the specified dir
video = Video("video.mp4")
# Start the video
video.play()
# Main loop
while True:
...
# Draw video to display surface
# this function should be called every frame
video.draw_to(window, (0, 0))
# Update pygame display
pygame.display.flip()- Python 3.9+
- Pygame Community Edition 2.2.0+
- NumPy
- OpenCV
- FFPyPlayer
You can just use the docstrings as well.
Pygame video player class.
-
filepath: Filepath of the video source. -
is_ready: Is the video source loaded and ready to play?frame_width: Default frame width in pixels.frame_height: Default frame height in pixels.is_playing: Is the video currently playing?is_paused: Is the video currently paused?is_looped: Is looping enabled?volume: Volume of the audio.is_muted: Is the audio muted?fps: Framerate of the video.total_frames: Total amount of frames of the video.duration: Total duration of the video in milliseconds.current_time: Current time into the video in milliseconds.remaining_time: Remaining time left in the video in milliseconds.current_frame: Current frame into the video.remaining_frames: Remaining frames left in the video.current_time: Current time into the video in milliseconds.
-
load(filepath: Union[str, os.PathLike]): Load a video from file path. This method is also called implicitly when instantiated.reload(): Reload the video from the same filepath.release(): Release the resources used by the video player.play(loop: bool = False): Start playing the video.stop(): Stop playing the video.pause(): Pause the video.resume(): Resume the video.toggle_pause(): Switch between paused states.mute(): Mute audio playback.unmute(): Unmute audio playback.seek_time(timepoint: float): Seek into desired timepoint.seek_frame(frame: int): Seek into desired frame.get_frame(): Advance the video and return the current frame. Must be called once per frame.draw_to(dest_surface: pygame.Surface, position: Coordinate): Blit the current video frame to the surface.
MIT © Kadir Aksoy