I added a way to listen to audio. First time you run the example.py (or your script), it will create an mp3 (it needs ffmpeg installed). Then it will play the mp3 with the audio togheter with the video using pygame (you have to pip install pygame). Tha's all. See ya. To install tkvideoaudio (not tkvideo) write this:
pip install tkvideoaudio@git+https://github.com/formazione/tkvideoaudio
Then use the same example:
''' to install tkvideoaudio
pip install tkvideoaudio@git+https://github.com/formazione/tkvideoaudio
'''
import tkinter as tk
from tkvideoaudio import tkvideo
import pygame
root = tk.Tk()
root.title("video play")
label_video=tk.Label(root)
label_video.pack()
video_file=tkvideo("001.mp4",label_video,loop=1,size=(800,600))
video_file.play()
root.mainloop()
pygame.quit()Change the name of the video as the name of your video, add a path if it is not in the folder where you are working. The first time it will get the audio from the video and play it along. The following times there will be no need to get the audio again. To get the audio it needs ffmp, so install it, it's free and very useful to elaborate audio, video, convert formats etc.
NOTE: This repository is archived as I'm no longer able to work on this project. Thanks to everyone who contributed to this.
Python module for playing videos (without sound) inside tkinter Label widget using Pillow and imageio
tkVideo is a Python module for playing videos in GUIs created with tkinter. It does so by binding to a tkinter.Label widget of the user's choice and rapidly changing its image object.
- Clone the repo and run
setup.py
git clone https://github.com/huskeee/tkvideo.git
python ./tkvideo/setup.pyor
- Install the package from PyPI (tkvideoaudio is not on PyPI)
pip install tkvideo- Clone the repo and install the module in developer mode
git clone https://github.com/formazione/tkvideoaudio.git
python ./tkvideoaudio/setup.py developor
- Install the package from PyPI in editable mode (tkvideoaudio is not on PyPI)
pip install -e tkvideoThis will create a shim between your code and the module binaries that gets updated every time you change your code.
- Import tkinter and tkvideo
- Create
Tk()parent and the label you'd like to use - Create
tkvideoobject with its parameters (video file path, label name, whether to loop the video or not and size of the video) - Start the player thread with
<player_name>.play() - Start the Tk main loop
Example code:
from tkinter import *
from tkvideo import tkvideo
root = Tk()
my_label = Label(root)
my_label.pack()
player = tkvideo("C:\\path\\to\\video.mp4", my_label, loop = 1, size = (1280,720))
player.play()
root.mainloop()Have a problem that needs to be solved or a suggestion to make? See the issues page.
Distributed under the MIT License. See LICENSE for more information.
Xenofon Konitsas - @huskeeeeee - konitsasx@gmail.com
Project Link: https://github.com/huskeee/tkvideo
- @Pythonista on StackOverflow for the frame loading code