Smallest VideoPlayer ever

Here is a script to see a movie in mp4 format using Python and Pygame

from moviepy.editor import *
import pygame

pygame.display.set_caption('Hello World!')
#pygame.display.set_mode((0,0), 0, 32)
clip = VideoFileClip('00.mp4')
clip.preview()

pygame.quit()

Create a function to play the movie

from moviepy.editor import *
import pygame


def launch(movie):
    pygame.display.set_caption('Hello World!')
    clip = VideoFileClip(movie)
    clip.preview()
    pygame.quit()


launch("00.mp4")

Using tkinter as a menu

from moviepy.editor import *
import pygame
import tkinter as tk
from glob import glob


def launch(movie):
    # root.destroy()
    pygame.display.set_caption('Hello World!')
    clip = VideoFileClip(movie)
    clip.preview()
    pygame.quit()


# launch("00.mp4")

root = tk.Tk()
root.geometry("400x300")
root.title("Double click to start")
x = tk.StringVar(value=[m for m in glob("*.mp4")])

ls = tk.Listbox(root, listvariable=x)
ls.pack(fill="both", expand=1)
ls.bind("<Double-Button>", lambda x: launch(ls.get(ls.curselection())))

root.mainloop()


Rotate the screen

clip = VideoFileClip(movie).rotate(180)

Show length and frame rate

print("Duration : ", clip.duration//60, "minutes")
print("FPS : ", clip.fps)

Saving a clip from a movie

from moviepy.editor import *
import pygame
import tkinter as tk
from glob import glob


def launch(movie):
    pygame.display.set_caption('Hello World!')
    clip = VideoFileClip(movie)
    # clip = VideoFileClip(movie).rotate(180)
    clip.preview()
    pygame.quit()
    print("Duration : ", clip.duration // 60, "minutes")
    print("FPS : ", clip.fps)


def save_clip(movie, title="Movie clip", start=50, end=60):

    video = VideoFileClip(movie).subclip(start, end)
    txt_clip = (
        TextClip(title, fontsize=70, color='white')
        .set_position('center')
        .set_duration(10))
    result = CompositeVideoClip(
[video, txt_clip]
)
    result.write_videofile(
        "myHolidays_edited.mp4", fps=10)


# launch("00.mp4")
root = tk.Tk()
root.geometry("400x300")
root.title("Double click to start")
x = tk.StringVar(value=[m for m in glob("*.mp4")])

ls = tk.Listbox(root, listvariable=x)
ls.pack(fill="both", expand=1)
ls.bind("<Double-Button>", lambda: launch(ls.get(ls.curselection())))

button = tk.Button(root, text="clip the selected movie",
    command=lambda: save_clip(ls.get(ls.curselection())))
button.pack()

root.mainloop()

 


Subscribe to the newsletter for updates
Tkinter templates
My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts