pygamevideo module helps developer to embed videos into their Pygame display

Overview

Pygame Video Player

pygamevideo module helps developer to embed videos into their Pygame display. Audio playback doesn't use pygame.mixer.

Installing

pip install pygamevideo

or just copy-paste pygamevideo.py to your working directory

Usage

import pygame
from pygamevideo import Video

window = pygame.display.set_mode()

video = Video("video.mp4")

# start video
video.play()

# main loop
while True:
  ...

  # draw video to display surface
  # this function must be called every tick
  video.draw_to(window, (0, 0))

  # set window title to current duration of video as hour:minute:second
  t = video.current_time.format("%h:%m:%s")
  pygame.display.set_caption(t)

Dependencies

Reference

class Video(filepath)

Pygame video player class

Parameters

filepath : Filepath of the video source

Methods & Attributes

load(filepath) : Load another video source


release() : Release resources

Related to playback control

play(loop=True) : Starts video playback

  • loop : Is video looped or not

restart() : Restarts already playing video


stop() : Stops video


pause() : Pauses video


resume() : Resumes video


is_playing : Whether the video is playing or not (bool)


is_ended : Whether the video has ended or not (bool)


is_paused : Whether the video is paused or not (bool)


is_ready : Whether the resources and video is ready to play (bool)

Related to audio control

mute() : Mutes audio


unmute() : Unmutes audio


has_audio() : NOT IMPLEMENTED


set_volume(volume) : Sets audio volume

  • volume : Floating number between 0.0 and 1.0

is_muted : Whether the audio is muted or not (bool)


volume : Audio volume (float)

Related to timing control

duration : Length of the video as Time object


current_time : Current time of the video as Time object


remaining_time : Remaining time till the end of the video as Time object


total_frames : Length of the video as frames (int)


current_frame : Current frame of the video (int)


remaining_frames : Remaining frames till the end of the video (int)


seek_time(t) : Jump into a specific time of the video

  • t : Time object
  • t : Representation of time in string, eg: "00:01:05:200" meaning 1 minute, 5 seconds and 200 milliseconds (str)
  • t : Milliseconds (int)

seek_frame(frame) : Jump into a specific frame of the video

  • frame : Frame number (int)

Related to resizing & frame dimensions

get_size() : Returns video size (tuple)


get_width() : Returns video width (int)


get_height() : Returns video height (int)


set_size(size) : Resizes video

  • size : New size (tuple)

set_width(width) : Resizes video

  • width : New width (int)

set_height(height) : Resizes video

  • height : New height (int)

keep_aspect_ratio : Keeps original aspect ratio while resizing the video (bool)

Drawing the video

draw_to(surface, pos) : Draws the video onto the surface. This functions must be called every tick.

  • surface : Destination surface (pygame.Surface)
  • pos : Blitting position (tuple)

get_frame() : Returns the current video frame as pygame.Surface. This function is used by draw_to function, so use only one of both each tick

class Time

Data class used to represent duration and such things by Video class

You might also like...
Youtube as covert-channel - Control systems remotely and execute commands by uploading videos to Youtube
Youtube as covert-channel - Control systems remotely and execute commands by uploading videos to Youtube

covert-tube A program to control systems remotely by uploading videos to Youtube using Python to create the videos and the listener, emulating some ma

Text2Video's purpose is to help people create videos quickly and easily by simply typing out the video’s script and a description of images to include in the video.
Text2Video's purpose is to help people create videos quickly and easily by simply typing out the video’s script and a description of images to include in the video.

Text2Video Text2Video's purpose is to help people create videos quickly and easily by simply typing out the video’s script and a description of images

Script simples para baixar vídeos/áudios/playlist do YouTube

🔗 VilelaTube ▶️ Script simples para baixar vídeos/áudios/playlist do YouTube Requisitos • Como usar • Melhorias futuras ⚠️ Atenção! ⚠️ Lembre-se de a

A GUI based datamoshing apllication for everyone! Apply this glitch to your videos and gifs. Supports all video formats!
A GUI based datamoshing apllication for everyone! Apply this glitch to your videos and gifs. Supports all video formats!

A GUI based datamoshing apllication for everyone! Apply this glitch to your videos and gifs. Supports all video formats!

A simple Telegram bot to extract hard-coded subtitle from videos using FFmpeg & Tesseract.

Video Subtitle Extractor Bot A simple Telegram bot to extract hard-coded subtitle from videos using FFmpeg & Tesseract. Note that the accuracy of reco

DICexport is a GUI (PyQt5) to export digital image correlation videos

DIC Video Exporter DICexport is a GUI (PyQt5) to export digital image correlation videos. It offers the flexibility to choose a selected range of a vi

Add the dislike count back to my YouTube videos via a comment containing that information.

YouTube Dislikes Forrest Knight Python Version 3.0+ Only use if you know what the code actually does. I'm not responsible for your use of this code in

Program to play videos with props in Apex Legends

R5Fresh A video player for the Apex Legends mod R5Reloaded

A telegram bot for compressing/encoding videos in h264 format.

Video-Encoder-Bot a telegram bot for compressing/encoding videos in h264 format. Configuration Add values in environment variables or add them in conf

Comments
  • `No such file or directory: 'requirements.txt'` on pip install

    `No such file or directory: 'requirements.txt'` on pip install

    Collecting pygamevideo
      Downloading pygamevideo-1.0.0.tar.gz (2.6 kB)
      Preparing metadata (setup.py) ... error
      error: subprocess-exited-with-error
      
      × python setup.py egg_info did not run successfully.
      │ exit code: 1
      ╰─> [6 lines of output]
          Traceback (most recent call last):
            File "<string>", line 2, in <module>
            File "<pip-setuptools-caller>", line 34, in <module>
            File "/tmp/pip-install-1ro6jb45/pygamevideo_e6ada7d091a54e58a1dbb58db3f3fafe/setup.py", line 28, in <module>
              install_requires=open("requirements.txt", "r").readlines()
          FileNotFoundError: [Errno 2] No such file or directory: 'requirements.txt'
          [end of output]
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
    error: metadata-generation-failed
    
    × Encountered error while generating package metadata.
    ╰─> See above for output.
    
    note: This is an issue with the package mentioned above, not pip.
    hint: See above for details.
    

    You forgot to add the requirements.txt I think

    opened by NicolasMICAUX 0
  • seek_time has a bug

    seek_time has a bug

    seek_time(12) seek_time(15) ...... the seconds is not a multiple of 10, then audio and video are out of sync.

    why don't use self.ff.get_frame() to get a frame?

    opened by zsmsky 0
Owner
Kadir Aksoy
A believer in gravity.
Kadir Aksoy
Convert lecture videos to slides in one line. Takes an input of a directory containing your lecture videos and outputs a directory containing .PDF files containing the slides of each lecture.

Convert lecture videos to slides in one line. Takes an input of a directory containing your lecture videos and outputs a directory containing .PDF files containing the slides of each lecture.

Sidharth Anand 12 Sep 10, 2022
A Telegram bot to convert videos into x265/x264 format via ffmpeg.

Video Encoder Bot A Telegram bot to convert videos into x265/x264 format via ffmpeg. Configuration Add values in environment variables or add them in

Adnan Ahmad 82 Jan 3, 2023
A Telegram bot to convert videos into x265/x264 format via ffmpeg.

Video Encoder Bot A Telegram bot to convert videos into x265/x264 format via ffmpeg. Configuration Add values in environment variables or add them in

null 1 Mar 8, 2022
Python package to display video in GUI using OpenCV-Python and PySide6

Python package to display video in GUI using OpenCV-Python and PySide6. Introduction cv2PySide6 is a package which provides utility classes and functi

null 3 Jun 6, 2022
Terminal-Video-Player - A program that can display video in the terminal using ascii characters

Terminal-Video-Player - A program that can display video in the terminal using ascii characters

null 15 Nov 10, 2022
It is a simple python package to play videos in the terminal using characters as pixels

It is a simple python package to play videos in the terminal using characters as pixels

Joel Ibaceta 1.4k Jan 7, 2023
Python Script for Streaming YouTube Videos in VLC Media Player.

Short Description Use this Simple Script to stream YouTube Video to VLC

Sijey 6 May 27, 2021
Playing videos through S3 buckets (Wasabi, AWS, etc.) through client-side VideoJS player

Playing videos through S3 buckets (Wasabi, AWS, etc.) through client-side VideoJS player without incurring ingress/egree traffic on EC2 Instance.

Syed Umar Arfeen 8 Mar 28, 2022
A python generator that converts youtube videos to ascii art in your console.

Video To ASCII A python generator that converts youtube videos to ascii art in your console. This has not been tested for windows! Example Normal mode

Julian Jones 24 Nov 2, 2022
goal: render videos on eu4's timeline function

Rendering Videos on the EU4 Time Line This repository contains code to create an eu4-savefile that plays back a video in question.

null 29 Dec 24, 2022