老猿前面有篇文章《moviepy应用pyinstaller打包后执行报错AttributeError: module audio/video.fx.all has no attribute ‘fadein’、crop》,今天居然发现有人原文照抄还获了很多个赞,而老猿的原文居然还没有赞。抄袭文章链接为:https://www.pythonheidong.com/blog/article/314732/。并且这篇文章今天仔细核对了一下,还有错误,在此更正一下。
原文解决办法部分,“如针对audio.fx.all,在Python中手工执行如下代码:”
import pkgutil
import moviepy.video.fx as fx
__all__ = [name for _, name, _ in pkgutil.iter_modules(fx.__path__) if name != "all"]
for name in __all__:
print("from moviepy.video.fx import %s" % (name))
实际上这个地方应该这样处理:
>>> import pkgutil
>>> import moviepy.audio.fx as fx
>>> __all__ = [name for _, name, _ in pkgutil.iter_modules(
fx.__path__) if name != "all"]
>>> for name in __all__:
print("from moviepy.audio.fx import %s" % (name))
from moviepy.audio.fx import audio_fadein
from moviepy.audio.fx import audio_fadeout
from moviepy.audio.fx import audio_left_right
from moviepy.audio.fx import audio_loop
from moviepy.audio.fx import audio_normalize
from moviepy.audio.fx import volumex
>>>
将上面的输出语句拷贝到audio.fx.all的__init__.py,替换被注释的2行代码即可。如movipy1.03的版本中,拷贝到audio.fx.all的__init__.py文件后,该文件内容为如下:
"""
Loads all the fx !
Usage:
import moviepy.audio.fx.all as afx
audio_clip = afx.volume_x(some_clip, .5)
"""
import pkgutil
import moviepy.audio.fx as fx
__all__ = [name for _, name, _ in pkgutil.iter_modules(
fx.__path__) if name != "all"]
#for name in __all__:
exec("from ..%s import %s" % (name, name))
#for name in __all__:
# print("from moviepy.audio.fx import %s" % (name))
from moviepy.audio.fx import audio_fadein
from moviepy.audio.fx import audio_fadeout
from moviepy.audio.fx import audio_left_right
from moviepy.audio.fx import audio_loop
from moviepy.audio.fx import audio_normalize
from moviepy.audio.fx import volumex
老猿的付费专栏《使用PyQt开发图形界面Python应用》专门介绍基于Python的PyQt图形界面开发基础教程,付费专栏《moviepy音视频开发专栏》详细介绍moviepy音视频剪辑合成处理的类相关方法及使用相关方法进行相关剪辑合成场景的处理,两个专栏加起来只需要19.9元,都适合有一定Python基础但无相关专利知识的小白读者学习。这2个收费专栏都有对应免费专栏,只是收费专栏的文章介绍更具体、内容更深入、案例更多。
对于缺乏Python基础的同仁,可以通过老猿的免费专栏《专栏:Python基础教程目录》从零开始学习Python。
如果有兴趣也愿意支持老猿的读者,欢迎购买付费专栏。