Pyvidplayer - An extremely easy to use module that plays videos on Pygame

Overview

pyvidplayer

An extremely easy to use module that plays videos on Pygame

Example

import pygame
from pyvidplayer import Video

pygame.init()
win = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()

#provide video class with the path to your video
vid = Video("4.mp4")
vid.set_size((1280, 720))

while True:
    key = None
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            #release video resources when done
            vid.close()
            pygame.quit()
            exit()
        elif event.type == pygame.KEYDOWN:
            key = pygame.key.name(event.key)
    
    #your program frame rate does not affect video playback
    #more info below
    clock.tick(60)
    
    if key == "r":
        vid.restart()           #rewind video to beginning
    elif key == "p":
        vid.toggle_pause()      #pause/plays 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 - mute
        
    #draws the video to the given surface, at the given position
    #info on force draw below
    vid.draw(win, (0, 0), force_draw=False)
    
    pygame.display.update()

Features:

  • Standard video playing features such as seeking and pausing
  • Internal clock plays video at the right pace regardless of your program's fps (try changing the clock.tick() values in the above example and see for yourself)
  • Uses Pygame surfaces for more user control
  • Minimal cpu usage (on my machine, max optimization used less than 10%, min used 20%, and a practical approach used around 12%)
  • Add a video to your game in just 3 lines of code

Other Stuff

  • get_file_data() returns a bunch of information regarding the video file, such as frame count, duration, size, etc
  • get_playback_data() returns information regarding the video class itself, such as it's volume, pause state, etc
  • For draw(), the force_draw parameter is defaulted to True. That means that everytime the method is called, the current video frame will be drawn. When force_draw is turned off, draw() will only draw something when there is a new frame in the video. Otherwise, it draws nothing. This is nice to save cpu, as you don't need to keep drawing the same frame over and over again. However, there will be a lot of flickering if stuff is drawn above or below the frame, which is why force_draw is defaulted to True
  • Seeking backwards is a lot slower than seeking forwards
  • video.active will become False when the video finishes playing
Owner
I am a student who enjoys Python.
A puzzle game coded entirely in Python.

Pyzzle A puzzle game coded entirely in Python. This is a school project created by me, Mohit Singh. The .exe file, created from the main.py script, is

Mohit Singh 1 Mar 19, 2022
A converter for the .BMR / .RLE bitmap files used in some Neversoft PS1 games.

Requirements python3 pyqt5 - can be installed with pip install PyQt5 pypng - Included Usage Instructions This program can be running py main.py in the

4 Jul 30, 2022
This is a classic guess coin game (Heads or Tails) implemented by the Chialisp.

This is a classic guess coin game (Heads or Tails) implemented by the Chialisp. It is an absolutely fair P2P game based on the Chia blockchain. You can play with anyone in the world without custody.

Kronus91 14 Jul 02, 2022
Minecraft Script to Tellraw Datapack Generator

Minecraft Script to Tellraw Datapack Geneator (STDG) can generate a chain of tellraw command in datapack from script.

1 Jan 28, 2022
For the Exapunk minigame, ПАСЬЯНС

Exapunks Automation This repository solves Exapunk's Solitaire minigame, ПАСЬЯНС. This repository is useable, but only with specific display condition

Will C 5 Jul 29, 2022
PyUnity is a Python implementation of the Unity Engine, written in C++

PyUnity is a Python implementation of the Unity Engine, written in C++. This is just a fun project and many features have been taken out to make it as easy as possible to create a scene and run it.

PyUnity 206 Jan 03, 2023
A Game Engine Made in Python with the Pygame Module

MandawEngine A Game Engine Made in Python with the Pygame Module Discord: https://discord.gg/MPPqj9PNt3 Installation To Get The Latest Version of Mand

Mandaw 14 Jun 24, 2022
Playing memory game is fun and the more harder it is the more challenging it is.

Playing memory game is fun and the more harder it is the more challenging it is. Playing thi sgame make us stress free and also happy. So, I have decided to make a memory Game which people can play w

Shreejan Dolai 3 Nov 11, 2022
A coven of tools to assist in PnP RPGs.

pupillae A coven of tools to assist PnP RPGs. Status: Pre-alpha. Testing. Adding necessary functions and features as discovered/required. Other-than-P

0 Dec 09, 2021
A module for use with Pygame. Includes fully customisable buttons, textboxes, sliders and many more, as well as the ability to create and run animations on these widgets.

Pygame Widgets A helper module for common widgets that may be required in developing applications with Pygame. It supports fully customisable buttons,

37 Jan 02, 2023
It calculates the Nim sum of a nim game.

nim-sum It calculates the Nim sum of a nim game. The rules of Nim The traditional game of Nim is played with a number of coins arranged in heaps: the

2 Jan 02, 2022
A first-person shooting game developed by using OpenGL

OpenGL-MazeSurvivor-FirstPerson Shooting Game This application named ‘MAZE SURVIVOR’ is a first-person shooting game that finished within a month. It

JunHong 2 Jan 04, 2023
Chess game for 2 players with UI

2-D Chess for 2 players Overview This is a simple 2D Chess game for 2 players using pygame library. Requirements To be able to run this game, you must

7 Apr 06, 2022
TicTacToc - Simple TicTacToc game played by minimax algorithm

TicTacToc simple TicTacToc game played by minimax algorithm. This app is based o

5 Apr 05, 2022
Tool for Path of Exile game to automatically scan Archemesis inventory and display related information

poe-archnemesis-scanner Tool for Path of Exile game to automatically scan Archemesis inventory and display related information Features Controls When

70 Nov 10, 2022
An single python server emulator of MMORPG game WindSlayer also known as WS1.

PySlayer An single python server emulator of MMORPG game WindSlayer also known as WS1. Requirements Python = 3.7 Old windslayer client (Korea Yahoo!

mirusu400 29 Dec 19, 2022
Adventure-Game - Adventure Game which is created using Python

Adventure Game 🌇 This is a Adventure Game which is created using Python. Featur

ArinjoyTheDev 1 Mar 19, 2022
A python game engine.

PursuedPyBear, also known as ppb, exists to be an educational resource. Most obviously used to teach computer science, it can be a useful tool for any topic that a simulation can be helpful.

PPB 235 Jan 08, 2023
Logo hitting the corner == best feeling ever!

Bouncing DVD logo - Pygame A little ride back to the 90s. Ah good ol' time! Didn't we all wait for the logo to hit the corners? Best feeling ever!! I

Hoang Nguyen 3 May 25, 2022
Exposè for i3 WM. Fork of https://gitlab.com/d.reis/i3expo to fix crashes and improve features/usability

Overwiew Expo is an simple and straightforward way to get a visual impression of all your current virtual desktops that many compositing window manage

137 Nov 03, 2022