如何解决此错误:AttributeError: 'NoneType' object has no attribute 'write_audiofile'

问题描述

import moviepy.editor
# Replace the parameter with the location of the video


video = moviepy.editor.VideoFileClip("/home/amit/video2.mp4")
audio = video.audio


# Replace the parameter with the location along with filename
audio.write_audiofile("/home/amit/output.mp3")

这是代码并收到此错误

AttributeError: 'nonetype' object has no attribute 'write_audiofile'

解决方法

看起来video.audio的值是None,这是python的空值。

空值没有任何属性,因此在尝试访问不存在的属性时会收到 AttributeError。

在这种特定情况下,这可能意味着 moviepy 无法在 video2.mp4 中找到音频。

您可以通过拨打以下电话获得更多信息:

print(video.reader.infos)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...