解决Python3使用moviePy编辑视频时,clip.show()卡顿
2021/11/13 14:09:42
本文主要是介绍解决Python3使用moviePy编辑视频时,clip.show()卡顿,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
按照官方的说明,clip.show()是利用pygame模块来展示的,pygame在显示图像时需要加入以下代码防止卡顿
for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit()
于是为方便后续的调试,封装了一个对象
import threading from moviepy.editor import * import pygame class video(threading.Thread): def __init__(self, clip): threading.Thread.__init__(self) self.clip = clip def show(self, timing:float=0, interactive:bool=False): show_clip(self.clip, timing, interactive) def preview(self, fps:int = 0, audio:bool = True): preview(self.clip, fps=fps, audio=audio) def show_clip(clip, timing:float=0, interactive:bool = False): if timing > 0: clip.show(timing, interactive=interactive) else: clip.show(interactive=interactive) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() def preview(clip, fps:int = 0, audio:bool = True): if fps > 0: clip.preview(fps=fps, audio=audio) else: clip.preview(audio=audio) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() clip1 = VideoFileClip('abc.mp4') video(clip1).show()
这里顺便把preview方法也封装了一下(实测preview好像是不会造成卡顿)
这样以后直接用video(clip).show()方法即可预览首帧,
video(clip).show(5, interactive=True) 预览5秒位置的首帧,并开启交互模式
这篇关于解决Python3使用moviePy编辑视频时,clip.show()卡顿的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python