问题描述
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)