Run a video in tkinter with tkvideo with audio too

This is the way I made the video go with the audio with tkvideo, for sure there are better ways

You have to get the audio first with get_audio() and then you start with the start() function. Change the name of the file and the path.

import tkinter as tk
from tkvideo import tkvideo
import pygame
import os



def get_audio(file):
	from moviepy.editor import VideoFileClip

	# Load the MP4 file
	video = VideoFileClip(file + ".mp4")

	# Extract the audio
	audio = video.audio

	# Save the audio as an MP3 file
	audio.write_audiofile(file + ".mp3")


def start(file):
	if not file + ".mp3" in os.listdir("."):
		get_audio(file)
	pygame.init()
	pygame.mixer.init()
	pygame.mixer.music.load(file + ".mp3")
	root = tk.Tk()
	# root.geometry("640x480")

	videoPlayer = tk.Label(root)
	videoPlayer.pack()
	video = tkvideo(file + ".mp4", videoPlayer, loop=1, size=(640,480))
	video.play()
	pygame.mixer.music.play()
	root.mainloop()


start("froggo")

Subscribe to the newsletter for updates
Tkinter templates
Avatar My youtube channel

Twitter: @pythonprogrammi - python_pygame

Videos

Speech recognition game

Pygame's Platform Game

Other Pygame's posts

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.