如何使用toypy.editor执行clip.preview()和同时循环

发布于 2025-02-06 19:36:54 字数 1431 浏览 3 评论 0原文

我的目标是,当您在显示idle.preview()时按空格时,它会播放另一个视频(end.preview())。它将重复电影,直到按下空间为止。 但是preview()将整个视频执行,因此我使用了多处理和线程 要拥有它和while loop 如果键盘。IS_PREDSERS执行parallelly,但是即使有了它,我也必须等待预览完成,然后才能按下空格...我尝试放置当函数中循环并将其放入第二个线程/进程中时,但是它给出了相同的结果...并且通过过程,即使我将放置___name __ =,脚本也从开始时从开始时重新启动。 __MAIN __ Process(target = idle())。start()。我该如何实现目标?

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')

注意:我的代码位于一个try-except块中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文