最近在使用用moviepy写一个视频转gif的程序,中间遇到了两个很多人遇到的问题。
1、moviepy.editor报错
这个和moviepy版本有关系,升级到最新版本之后,这个方法已经被弃用了。所以会报错,
以前是from moviepy.editor import VideoFileClip
升级之后用是这样导入的:
from moviepy import VideoFileClip
可以去看下官方的最新版本的介绍文档
2、关于封装封装后报错的原因
我的程序界面是这样的:
封装之后,就展示数据执行状态,和运行日志,在运行日志中,会打印出需要查看的日志信息,但是moviepy会调用的 dos窗口展示一个进度条,不管是视频合成还是视频转gif,write方法下面会有一个logger字段,这个是进度条,默认值:bar,也就是展示进度条,可以看下下面的方法:
@requires_duration
@convert_masks_to_RGB
@convert_path_to_string("filename")
def write_gif(
self,
filename,
fps=None,
loop=0,
logger="bar",
):
"""Write the VideoClip to a GIF file.
Converts a VideoClip into an animated GIF using imageio
Parameters
----------
filename
Name of the resulting gif file, as a string or a path-like object.
fps
Number of frames per second (see note below). If it
isn't provided, then the function will look for the clip's
``fps`` attribute (VideoFileClip, for instance, have one).
loop : int, optional
Repeat the clip using ``loop`` iterations in the resulting GIF.
progress_bar
If True, displays a progress bar
Notes
-----
The gif will be playing the clip in real time (you can
only change the frame rate). If you want the gif to be played
slower than the clip you will use
.. code:: python
# slow down clip 50% and make it a gif
myClip.multiply_speed(0.5).to_gif('myClip.gif')
"""
# A little sketchy at the moment, maybe move all that in write_gif,
# refactor a little... we will see.
write_gif_with_imageio(
self,
filename,
fps=fps,
loop=loop,
logger=logger,
)
当我们调用这个方法的时候,会调用dos,如果调用不到就会报错。
解决办法:logger=None
sub_clip.write_gif(output_path, fps=10, logger=None)
我们在调用这个方法的时候,logger设置成None,再进行封装 ,这是软件就可以正常运行了。