@QWERTYUIOPas

Как перебрать видео по звукам?

Как перебрать видео не по кадрам (как в спойлере), а по звукам чтобы их можно было проигрывать с помощью winsound.Beep()?
mytkvideo.py

try:
    import Tkinter as tk  # for Python2 (although it has already reached EOL)
except ImportError:
    import tkinter as tk  # for Python3
import threading
import imageio
from PIL import Image, ImageTk
class video():
    """ 
        Main class of tkVideo. Handles loading and playing 
        the video inside the selected label.
        
        :keyword path: 
            Path of video file
        :keyword label: 
            Name of label that will house the player
        :param loop:
            If equal to 0, the video only plays once, 
            if not it plays in an infinite loop (default 0)
        :param size:
            Changes the video's dimensions (2-tuple, 
            default is 640x360) 
    
    """
    canPlay=True
    def __init__(self, path, label, loop = 0, size = (640,360)):
        self.path = path
        self.label = label
        self.loop = loop
        self.size = size
    def load(self, path, label, loop):
        """
            Loads the video's frames recursively onto the selected label widget's image parameter.
            Loop parameter controls whether the function will run in an infinite loop
            or once.
        """
        frame_data = imageio.get_reader(path)

        if loop == 1:
            while True:
                for image in frame_data.iter_data():
                    if self.canPlay or image==frame_data.iter_data()[0]:
                        frame_image = ImageTk.PhotoImage(Image.fromarray(image).resize(self.size))
                        label.config(image=frame_image)
                        label.image = frame_image
        else:
            for image in frame_data.iter_data():
                if self.canPlay or image==frame_data.iter_data()[0]:
                    frame_image = ImageTk.PhotoImage(Image.fromarray(image).resize(self.size))
                    label.config(image=frame_image)
                    label.image = frame_image
                else:
                    while True:
                        if self.canPlay:
                            break
    def start(self):
        self.canPlay=True
    def pause(self):
        self.canPlay=False
    def play(self):
        """
            Creates and starts a thread as a daemon that plays the video by rapidly going through
            the video's frames.
        """
        thread = threading.Thread(target=self.load, args=(self.path, self.label, self.loop))
        thread.daemon = 1
        thread.start()

Это я расковырял и дописал библиотеку TkVideo)))))))
  • Вопрос задан
  • 34 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы