How to use fl_image function in Moviepy within Python?

user144600 picture user144600 · Dec 5, 2016 · Viewed 7.3k times · Source

I want to save a video into another file using different name. Thus, I have following codes to handle this question:

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

Also, I have

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

However, I got the following error:

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

I am not sure what's wrong with it, can someone tell me why?

Answer

Foxan Ng picture Foxan Ng · Dec 5, 2016

The fl_image function accepts an image function as parameter, so the parameter passed to the image function process_image_1 should be an image, but not the path to an image.

Remove the line img=mpimg.imread(image) and read the image file outside of the image function, e.g.

result = process_image(mpimg.imread(image))

and it shall work.