使用moviepy和ffmpeg写入视频文件时出错

问题描述

我第一次使用moviepy库。我有一个大约 7 小时的视频剪辑,我想把它剪成小剪辑。我有一个开始和结束时间的列表。

video = VideoFileClip("videoFile.mp4")
clips = []
for cut in cuts:
   clip = video.subclip(cut[0],cut[1])
   clips.append(clip)
clips
clip = video.subclip("7:32:18","7:38:38")
clips.append(clip)
for clip,title in zip(clips,title_list):
 clip.write_videofile(title + '.mp4',threads=8,fps=24,audio=True,codec='libx264',preset=compression)
video.close()

clips[] 包含剪辑的开始和结束时间。我也有一个标题列表,是从 youtube 上抓取的。我没有在这里列出这两个列表,但一个小例子可能是:

cuts = [('0:00','2:26'),('2:26','5:00'),('5:00','7:15'),('7:15','10:57'),('10:57','18:00'),('18:00','18:22'),('18:22','19:57'),('19:57','20:37'),('20:37','28:27'),('28:27','40:32'),('40:32','49:57'),...
title_list = ['Introduction (What is Todoist?),tech stack talk','Showing the final application (with dark mode!)','Installing create react app',"Clearing out what we don't need from create react app","Let's get building our components!",'Installing packages using Yarn','Building the Header component','Building the Content component',...
OSError: [Errno 32] broken pipe

MoviePy error: FFMPEG encountered the following error while writing file Introduction(WhatisTodoist?),techstacktalkTEMP_MPY_wvf_snd.mp3:

b'Introduction(WhatisTodoist?),techstacktalkTEMP_MPY_wvf_snd.mp3: Invalid argument\r\n'

In case it helps,make sure you are using a recent version of FFMPEG (the versions in the Ubuntu/Debian repos are deprecated).

以上是我在运行 write_videofile() 后遇到的错误。我查看了 github 上的文档和问题,我也尝试通过 pip 更新 ffmpeg。不知道为什么不能写入音频文件

解决方法

原因可能是文件名中的特殊字符。 至少在 Windows 上你不能有 '?'在文件名中。 您可以尝试其他名称来检查是否是这个问题。

相关问答

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