如何使用toypy.editor执行clip.preview()和同时循环
我的目标是,当您在显示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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论