Initial commit
This commit is contained in:
13
pyvidplayer2/examples/all_previews_demo.py
Normal file
13
pyvidplayer2/examples/all_previews_demo.py
Normal file
@@ -0,0 +1,13 @@
|
||||
'''
|
||||
This shows off each graphics api and their respective preview methods
|
||||
'''
|
||||
|
||||
|
||||
from pyvidplayer2 import Video, VideoTkinter, VideoPyglet, VideoPyQT
|
||||
|
||||
PATH = r"resources\trailer1.mp4"
|
||||
|
||||
Video(PATH).preview()
|
||||
VideoTkinter(PATH).preview()
|
||||
VideoPyglet(PATH).preview()
|
||||
VideoPyQT(PATH).preview()
|
||||
7
pyvidplayer2/examples/cel_shading_demo.py
Normal file
7
pyvidplayer2/examples/cel_shading_demo.py
Normal file
@@ -0,0 +1,7 @@
|
||||
'''
|
||||
This is an example of the cel shading post process you can apply to your videos
|
||||
'''
|
||||
|
||||
from pyvidplayer2 import Video, PostProcessing
|
||||
|
||||
Video(r"resources\medic.mov", post_process=PostProcessing.cel_shading).preview()
|
||||
13
pyvidplayer2/examples/custom_post_processing_demo.py
Normal file
13
pyvidplayer2/examples/custom_post_processing_demo.py
Normal file
@@ -0,0 +1,13 @@
|
||||
'''
|
||||
This example shows how you can merge and create new post processing functions
|
||||
'''
|
||||
|
||||
|
||||
from pyvidplayer2 import Video, PostProcessing
|
||||
|
||||
# applies a letterbox, cel shading, and greyscale to video
|
||||
|
||||
def custom_process(data):
|
||||
return PostProcessing.letterbox(PostProcessing.cel_shading(PostProcessing.greyscale(data)))
|
||||
|
||||
Video(r"resources\birds.avi", post_process=custom_process).preview()
|
||||
11
pyvidplayer2/examples/custom_subtitles_demo.py
Normal file
11
pyvidplayer2/examples/custom_subtitles_demo.py
Normal file
@@ -0,0 +1,11 @@
|
||||
'''
|
||||
This is an example of custom subtitle fonts
|
||||
'''
|
||||
|
||||
|
||||
from pyvidplayer2 import Subtitles, Video
|
||||
from pygame.font import Font
|
||||
|
||||
subtitles = Subtitles(r"resources\subs2.srt", font=Font(r"resources\font.ttf", 60), highlight=(255, 0, 0, 128), offset=500)
|
||||
|
||||
Video(r"resources\trailer2.mp4", subs=subtitles).preview()
|
||||
39
pyvidplayer2/examples/many_videos_demo.py
Normal file
39
pyvidplayer2/examples/many_videos_demo.py
Normal file
@@ -0,0 +1,39 @@
|
||||
'''
|
||||
This is an example of a VideoCollection, which allows you to treat a large
|
||||
amount of ParallelVideos as one
|
||||
'''
|
||||
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 import Video, VideoPlayer
|
||||
|
||||
win = pygame.display.set_mode((1066, 744))
|
||||
pygame.display.set_caption("video collection demo")
|
||||
|
||||
|
||||
videos = [VideoPlayer(Video(r"resources\billiejean.mp4"), (0, 0, 426, 240), interactable=False),
|
||||
VideoPlayer(Video(r"resources\trailer1.mp4"), (426, 0, 256, 144), interactable=False),
|
||||
VideoPlayer(Video(r"resources\medic.mov"), (682, 0, 256, 144), interactable=False),
|
||||
VideoPlayer(Video(r"resources\trailer2.mp4"), (426, 144, 640, 360), interactable=False),
|
||||
VideoPlayer(Video(r"resources\clip.mp4"), (0, 240, 256, 144), interactable=False),
|
||||
VideoPlayer(Video(r"resources\birds.avi"), (0, 384, 426, 240), interactable=False),
|
||||
VideoPlayer(Video(r"resources\ocean.mkv"), (426, 504, 426, 240), interactable=False)]
|
||||
|
||||
while True:
|
||||
key = None
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
[video.close() for video in videos]
|
||||
pygame.quit()
|
||||
exit()
|
||||
elif event.type == pygame.KEYDOWN:
|
||||
key = pygame.key.name(event.key)
|
||||
|
||||
pygame.time.wait(16)
|
||||
|
||||
win.fill("white")
|
||||
|
||||
[video.update() for video in videos]
|
||||
[video.draw(win) for video in videos]
|
||||
|
||||
pygame.display.update()
|
||||
32
pyvidplayer2/examples/parallel_playing_demo.py
Normal file
32
pyvidplayer2/examples/parallel_playing_demo.py
Normal file
@@ -0,0 +1,32 @@
|
||||
'''
|
||||
This is an example of two videos playing simultaneously
|
||||
'''
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 import Video
|
||||
|
||||
|
||||
win = pygame.display.set_mode((960, 360))
|
||||
pygame.display.set_caption("parallel playing demo")
|
||||
|
||||
vid1 = Video(r"resources\trailer1.mp4")
|
||||
vid1.resize((480, 360))
|
||||
|
||||
vid2 = Video(r"resources\trailer2.mp4")
|
||||
vid2.resize((480, 360))
|
||||
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
vid1.close()
|
||||
vid2.close()
|
||||
pygame.quit()
|
||||
exit()
|
||||
|
||||
pygame.time.wait(16)
|
||||
|
||||
vid1.draw(win, (0, 0))
|
||||
vid2.draw(win, (480, 0))
|
||||
|
||||
pygame.display.update()
|
||||
32
pyvidplayer2/examples/parallel_subtitles_demo.py
Normal file
32
pyvidplayer2/examples/parallel_subtitles_demo.py
Normal file
@@ -0,0 +1,32 @@
|
||||
'''
|
||||
This example shows how every video can play subtitles
|
||||
'''
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 import Video, Subtitles
|
||||
|
||||
|
||||
win = pygame.display.set_mode((960, 360))
|
||||
pygame.display.set_caption("parallel subtitles demo")
|
||||
|
||||
vid1 = Video(r"resources\trailer1.mp4", subs=Subtitles(r"resources\subs1.srt"))
|
||||
vid1.resize((480, 360))
|
||||
|
||||
vid2 = Video(r"resources\trailer2.mp4", subs=Subtitles(r"resources\subs2.srt"))
|
||||
vid2.resize((480, 360))
|
||||
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
vid1.close()
|
||||
vid2.close()
|
||||
pygame.quit()
|
||||
exit()
|
||||
|
||||
pygame.time.wait(16)
|
||||
|
||||
vid1.draw(win, (0, 0))
|
||||
vid2.draw(win, (480, 0))
|
||||
|
||||
pygame.display.update()
|
||||
59
pyvidplayer2/examples/pip_demo.py
Normal file
59
pyvidplayer2/examples/pip_demo.py
Normal file
@@ -0,0 +1,59 @@
|
||||
'''
|
||||
A quick example showing how pyvidplayer2 can be used in more complicated applications
|
||||
This is a Picture-in-Picture app
|
||||
'''
|
||||
|
||||
|
||||
import pygame
|
||||
from win32gui import SetWindowPos, GetCursorPos, GetWindowRect, GetForegroundWindow, SetForegroundWindow
|
||||
from win32api import GetSystemMetrics
|
||||
from win32con import SWP_NOSIZE, HWND_TOPMOST
|
||||
from win32com.client import Dispatch
|
||||
from pyvidplayer2 import VideoPlayer, Video
|
||||
from cv2 import INTER_AREA
|
||||
|
||||
|
||||
SIZE = (426, 240)
|
||||
FILE = r"resources\billiejean.mp4"
|
||||
|
||||
win = pygame.display.set_mode(SIZE, pygame.NOFRAME)
|
||||
|
||||
# creates the video player
|
||||
|
||||
vid = VideoPlayer(Video(FILE, interp=INTER_AREA), (0, 0, *SIZE))
|
||||
|
||||
# moves the window to the bottom right corner and pins it above other windows
|
||||
|
||||
hwnd = pygame.display.get_wm_info()["window"]
|
||||
SetWindowPos(hwnd, HWND_TOPMOST, GetSystemMetrics(0) - SIZE[0], GetSystemMetrics(1) - SIZE[1] - 48, 0, 0, SWP_NOSIZE)
|
||||
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
shell = Dispatch("WScript.Shell")
|
||||
|
||||
while True:
|
||||
events = pygame.event.get()
|
||||
for event in events:
|
||||
if event.type == pygame.QUIT:
|
||||
vid.close()
|
||||
pygame.quit()
|
||||
quit()
|
||||
|
||||
clock.tick(60)
|
||||
|
||||
# allows the ui to be seamlessly interacted with
|
||||
|
||||
touching = pygame.Rect(GetWindowRect(hwnd)).collidepoint(GetCursorPos())
|
||||
if touching and GetForegroundWindow() != hwnd:
|
||||
|
||||
# weird behaviour with SetForegroundWindow that requires the alt key to be pressed before it's called
|
||||
|
||||
shell.SendKeys("%")
|
||||
SetForegroundWindow(hwnd)
|
||||
|
||||
# handles video playback
|
||||
|
||||
vid.update(events, show_ui=touching)
|
||||
vid.draw(win)
|
||||
|
||||
pygame.display.update()
|
||||
10
pyvidplayer2/examples/playback_speed_demo.py
Normal file
10
pyvidplayer2/examples/playback_speed_demo.py
Normal file
@@ -0,0 +1,10 @@
|
||||
'''
|
||||
This example shows how you can control the playback speed of videos
|
||||
'''
|
||||
|
||||
|
||||
from pyvidplayer2 import Video
|
||||
|
||||
v = Video(r"resources\trailer1.mp4")
|
||||
v.set_speed(2) # twice as fast
|
||||
v.preview()
|
||||
42
pyvidplayer2/examples/post_processing_demo.py
Normal file
42
pyvidplayer2/examples/post_processing_demo.py
Normal file
@@ -0,0 +1,42 @@
|
||||
'''
|
||||
This example gives a side by side comparison between a few available post process effects
|
||||
'''
|
||||
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 import Video, PostProcessing
|
||||
|
||||
PATH = r"resources\ocean.mkv"
|
||||
|
||||
win = pygame.display.set_mode((960, 240))
|
||||
pygame.display.set_caption("post processing demo")
|
||||
|
||||
# using a video collection to play videos in parallel for a side to side comparison
|
||||
|
||||
videos = [Video(PATH, post_process=PostProcessing.sharpen),
|
||||
Video(PATH),
|
||||
Video(PATH, post_process=PostProcessing.blur)]
|
||||
|
||||
font = pygame.font.SysFont("arial", 30)
|
||||
surfs = [font.render("Sharpen", True, "white"), font.render("Normal", True, "white"), font.render("Blur", True, "white")]
|
||||
|
||||
|
||||
while True:
|
||||
key = None
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
[video.close() for video in videos]
|
||||
pygame.quit()
|
||||
exit()
|
||||
elif event.type == pygame.KEYDOWN:
|
||||
key = pygame.key.name(event.key)
|
||||
|
||||
pygame.time.wait(16)
|
||||
|
||||
for i, surf in enumerate(surfs):
|
||||
x = 320 * i
|
||||
videos[i].draw(win, (x, 0))
|
||||
pygame.draw.rect(win, "black", (x, 0, *surf.get_size()))
|
||||
win.blit(surf, (x, 0))
|
||||
|
||||
pygame.display.update()
|
||||
8
pyvidplayer2/examples/preview_demo.py
Normal file
8
pyvidplayer2/examples/preview_demo.py
Normal file
@@ -0,0 +1,8 @@
|
||||
'''
|
||||
This is the quickest and simplest way to play videos
|
||||
'''
|
||||
|
||||
|
||||
from pyvidplayer2 import Video
|
||||
|
||||
Video(r"resources\trailer1.mp4").preview()
|
||||
22
pyvidplayer2/examples/pyglet_demo.py
Normal file
22
pyvidplayer2/examples/pyglet_demo.py
Normal file
@@ -0,0 +1,22 @@
|
||||
'''
|
||||
This is a quick example of integrating a video into a pyglet project
|
||||
Double buffering is turned off to benefit from turning off force draw on the video
|
||||
'''
|
||||
|
||||
|
||||
import pyglet
|
||||
from pyvidplayer2 import VideoPyglet
|
||||
|
||||
video = VideoPyglet(r"resources\trailer1.mp4")
|
||||
|
||||
def update(dt):
|
||||
video.draw((0, 0), force_draw=False)
|
||||
if not video.active:
|
||||
win.close()
|
||||
|
||||
win = pyglet.window.Window(width=video.current_size[0], height=video.current_size[1], config=pyglet.gl.Config(double_buffer=False), caption=f"pyglet support demo")
|
||||
|
||||
pyglet.clock.schedule_interval(update, 1/60.0)
|
||||
|
||||
pyglet.app.run()
|
||||
video.close()
|
||||
33
pyvidplayer2/examples/pyqt6_demo.py
Normal file
33
pyvidplayer2/examples/pyqt6_demo.py
Normal file
@@ -0,0 +1,33 @@
|
||||
'''
|
||||
This is a quick example of integrating a video into a pyqt6 project
|
||||
'''
|
||||
|
||||
|
||||
from PyQt6.QtWidgets import QApplication, QMainWindow, QWidget
|
||||
from PyQt6.QtCore import QTimer
|
||||
from pyvidplayer2 import VideoPyQT
|
||||
|
||||
|
||||
class Window(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.canvas = QWidget(self)
|
||||
self.setCentralWidget(self.canvas)
|
||||
|
||||
self.timer = QTimer(self)
|
||||
self.timer.timeout.connect(self.update)
|
||||
self.timer.start(16)
|
||||
|
||||
def paintEvent(self, _):
|
||||
video.draw(self, (0, 0))
|
||||
|
||||
|
||||
video = VideoPyQT(r"resources\trailer1.mp4")
|
||||
|
||||
app = QApplication([])
|
||||
win = Window()
|
||||
win.setWindowTitle(f"pyqt6 support demo")
|
||||
win.setFixedSize(*video.current_size)
|
||||
win.show()
|
||||
app.exec()
|
||||
video.close()
|
||||
32
pyvidplayer2/examples/queue_demo.py
Normal file
32
pyvidplayer2/examples/queue_demo.py
Normal file
@@ -0,0 +1,32 @@
|
||||
'''
|
||||
This example shows how videos can be queued and skipped through with the VideoPlayer object
|
||||
'''
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 import VideoPlayer, Video
|
||||
|
||||
win = pygame.display.set_mode((1280, 720))
|
||||
|
||||
|
||||
vid = VideoPlayer(Video(r"resources\clip.mp4"), (0, 0, 1280, 720), loop=True)
|
||||
|
||||
vid.queue(Video(r"resources\ocean.mkv"))
|
||||
vid.queue(Video(r"resources\birds.avi"))
|
||||
|
||||
|
||||
while True:
|
||||
events = pygame.event.get()
|
||||
for event in events:
|
||||
if event.type == pygame.QUIT:
|
||||
vid.close()
|
||||
pygame.quit()
|
||||
exit()
|
||||
elif event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
|
||||
vid.skip()
|
||||
|
||||
pygame.time.wait(16)
|
||||
|
||||
vid.update(events)
|
||||
vid.draw(win)
|
||||
|
||||
pygame.display.update()
|
||||
8
pyvidplayer2/examples/subtitles_demo.py
Normal file
8
pyvidplayer2/examples/subtitles_demo.py
Normal file
@@ -0,0 +1,8 @@
|
||||
'''
|
||||
This is an example showing how to add subtitles to a video
|
||||
'''
|
||||
|
||||
|
||||
from pyvidplayer2 import Subtitles, Video
|
||||
|
||||
Video(r"resources\trailer2.mp4", subs=Subtitles(r"resources\subs2.srt")).preview()
|
||||
27
pyvidplayer2/examples/tkinter_demo.py
Normal file
27
pyvidplayer2/examples/tkinter_demo.py
Normal file
@@ -0,0 +1,27 @@
|
||||
'''
|
||||
This is a quick example of integrating a video into a tkinter project
|
||||
'''
|
||||
|
||||
|
||||
import tkinter
|
||||
from pyvidplayer2 import VideoTkinter
|
||||
|
||||
video = VideoTkinter(r"resources\trailer1.mp4")
|
||||
|
||||
def update():
|
||||
video.draw(canvas, (video.current_size[0] / 2, video.current_size[1] / 2), force_draw=False)
|
||||
if video.active:
|
||||
root.after(16, update) # for around 60 fps
|
||||
else:
|
||||
root.destroy()
|
||||
|
||||
root = tkinter.Tk()
|
||||
root.title(f"tkinter support demo")
|
||||
|
||||
canvas = tkinter.Canvas(root, width=video.current_size[0], height=video.current_size[1], highlightthickness=0)
|
||||
canvas.pack()
|
||||
|
||||
update()
|
||||
root.mainloop()
|
||||
|
||||
video.close()
|
||||
46
pyvidplayer2/examples/video_demo.py
Normal file
46
pyvidplayer2/examples/video_demo.py
Normal file
@@ -0,0 +1,46 @@
|
||||
'''
|
||||
This is the same example from the original pyvidplayer
|
||||
The video class still does everything it did, but with many more features
|
||||
'''
|
||||
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 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(r"resources\medic.mov")
|
||||
|
||||
while True:
|
||||
key = None
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
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
|
||||
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
|
||||
|
||||
#draws the video to the given surface, at the given position
|
||||
vid.draw(win, (0, 0), force_draw=False)
|
||||
|
||||
pygame.display.update()
|
||||
30
pyvidplayer2/examples/videoplayer_demo.py
Normal file
30
pyvidplayer2/examples/videoplayer_demo.py
Normal file
@@ -0,0 +1,30 @@
|
||||
'''
|
||||
This is an example of the built in GUI for videos
|
||||
'''
|
||||
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 import VideoPlayer, Video
|
||||
|
||||
win = pygame.display.set_mode((1124, 868))
|
||||
pygame.display.set_caption("video player demo")
|
||||
|
||||
vid = VideoPlayer(Video(r"resources\ocean.mkv"), (50, 50, 1024, 768), preview_thumbnails=11)
|
||||
|
||||
|
||||
while True:
|
||||
events = pygame.event.get()
|
||||
for event in events:
|
||||
if event.type == pygame.QUIT:
|
||||
vid.close()
|
||||
pygame.quit()
|
||||
exit()
|
||||
|
||||
pygame.time.wait(16)
|
||||
|
||||
win.fill("white")
|
||||
|
||||
vid.update(events)
|
||||
vid.draw(win)
|
||||
|
||||
pygame.display.update()
|
||||
24
pyvidplayer2/examples/webcam_demo.py
Normal file
24
pyvidplayer2/examples/webcam_demo.py
Normal file
@@ -0,0 +1,24 @@
|
||||
'''
|
||||
Webcam example
|
||||
'''
|
||||
|
||||
import pygame
|
||||
from pyvidplayer2 import Webcam
|
||||
|
||||
webcam = Webcam()
|
||||
|
||||
win = pygame.display.set_mode(webcam.current_size)
|
||||
clock = pygame.time.Clock()
|
||||
|
||||
while True:
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
webcam.close()
|
||||
pygame.quit()
|
||||
exit()
|
||||
|
||||
clock.tick(60)
|
||||
|
||||
webcam.draw(win, (0, 0), force_draw=False)
|
||||
|
||||
pygame.display.update()
|
||||
Reference in New Issue
Block a user