Skip to main content
 首页 » 编程设计

python之如何在 Python 的 Moviepy 中使用 fl_image 函数

2025年05月04日15dudu

我想使用不同的名称将视频保存到另一个文件中。因此,我有以下代码来处理这个问题:

def process_image_1(image): 
  img=mpimg.imread(image) 
  return img; 

还有,我有

output='output.mp4' 
clip1 = VideoFileClip("Right.mp4") 
clip = clip1.fl_image(process_image_1) 
%time clip.write_videofile(output, audio=False) 

但是,我得到了以下错误:

Object does not appear to be a 8-bit string path or a Python file-like object 

我不确定它有什么问题,谁能告诉我为什么?

请您参考如下方法:

fl_image 函数接受图像函数作为参数,因此传递给图像函数 process_image_1 的参数应该是图像,而不是图像的路径。

删除行 img=mpimg.imread(image) 并在图像函数之外读取图像文件,例如

result = process_image(mpimg.imread(image)) 

它会起作用。