How to execute a clip.preview() with moviepy.editor and a while loop simultaneously

Viewed 73

My goal is that when you press space whenever idle.preview() is shown, it plays another video (end.preview()). It would repeat the movie until space is pressed. But preview() takes the whole video to execute, so I used multiprocessing and threads to have it and the while loop if keyboard.is_pressed to execute parallelly, but even with it, I have to wait for the preview to finish before being able to press space... I tried to put the while loop in a function and put it in a second thread/process, but it gives the same result... And with Process, the script restart from the beginning when the preview finishes, even when I put the if __name__ = __main__ before Process(target=idle()).start(). How could I reach my goal ?

from moviepy.editor import *
import keyboard
from multiprocessing import Process

    def Comp(p_start, p_idle, p_end):
        start = VideoFileClip(path % (drive, p_start))
        end = VideoFileClip(path % (drive, p_end))
        idle = VideoFileClip(path % (drive, p_idle))
        print('start playing')
        start.preview(fps=60)
        print('start playing end')

        def idle():
            idle = VideoFileClip(path % (drive, p_idle))
            print('idle playing')
            idle.preview(fps=60)
            print('idle playing end')
        start.close()
        Process(target=idle()).start()
        while True:
            if keyboard.is_pressed('space'):
                pygame.mixer.music.load('%s\...\Continue.wav' % drive)
                pygame.mixer.music.play()
                print('music played')
                break

    if __name__ == "__main__":
        Comp('Title incoming.mp4', 'Title incoming.mp4', 'Title incoming.mp4')

Note: My code is in a try-except block.

0 Answers
Related