Moviepy: Error with Pillow

Created on 23 Feb 2017  路  10Comments  路  Source: Zulko/moviepy

Hi,

I just wanted to start working with moviepy. But I ran into a problem that there seems to be a Pillow lib file is miss or so. First of all my code and the terminal output.
#!/usr/bin/env python
import moviepy.editor as mpy
clip1 = mpy.ColorClip((1280, 720), col=(255,0,0))
clip1 = clip1.set_duration(5)
clip2 = mpy.ImageClip("testimg.png")
clip2 = clip2.set_duration(10)
final_video = mpy.concatenate_videoclips([clip1, clip2], method="compose")
final_video.write_videofile("composition.mp4", fps=24)

Traceback (most recent call last):
File "mpy_test.py", line 8, in <module>
clip2 = mpy.ImageClip("testimg.png")
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", line 923, in __init__
img = imread(img)
File "/usr/local/lib/python2.7/dist-packages/imageio/core/functions.py", line 187, in imread
return reader.get_data(0)
File "/usr/local/lib/python2.7/dist-packages/imageio/core/format.py", line 241, in __exit__
self.close()
File "/usr/local/lib/python2.7/dist-packages/imageio/core/format.py", line 256, in close
self._close()
File "/usr/local/lib/python2.7/dist-packages/imageio/plugins/pillow.py", line 93, in _close
self._im.close()
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 528, in __getattr__
raise AttributeError(name)
AttributeError: close

I install Pillow with pip and I do find all mentioned files of imageio on my hard drive. But the PIL package is not there even thoughapt-get (Ubuntu14.04) says, it is installed. What could have gone wrong here?

Thanks

Florian

documentation

Most helpful comment

I'm not sure.. but I'll add a label for us to add this to the documentation.
Your modules look up to date, so I'm not sure what the problem is. Could you try reinstalling a few of them (imageio and pillow) and see if that helps?

All 10 comments

Florian,

This code works for me. What version of imageio do you have? maybe that is the issue?

Billy

Wow, that was a fast reply! Thanks for that.

I check with pip listand got the following:
imageio 2.1.2
moviepy 0.2.2.13
numpy 1.8.2
Pillow 2.3.0
pip 1.5.4

At the moviepy doc I could find a hint which version is required by the dependencies. Do you know more?

Florian

I'm not sure.. but I'll add a label for us to add this to the documentation.
Your modules look up to date, so I'm not sure what the problem is. Could you try reinstalling a few of them (imageio and pillow) and see if that helps?

Good advice! Pillow was creating the problem. I somehow got an old version via the Ubuntu repos. after killing that one and reinstalling 4.0.0 with pip it works.

But now I got an FFMPEG error.
[MoviePy] >>>> Building video composition.mp4
[MoviePy] Writing video composition.mp4
0%| 0/361 [00:00 Traceback (most recent call last):
File "mpy_test.py", line 12, in
final_video.write_videofile("composition.mp4", fps=24, audio=False)
File "", line 2, in write_videofile
File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 54, in requires_duration
return f(clip, a, *k)
File "", line 2, in write_videofile
File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 137, in use_clip_fps_by_default
return f(clip, new_a, *new_kw)
File "", line 2, in write_videofile
File "/usr/local/lib/python2.7/dist-packages/moviepy/decorators.py", line 22, in convert_masks_to_RGB
return f(clip, a, *k)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/VideoClip.py", line 338, in write_videofile
ffmpeg_params=ffmpeg_params)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/io/ffmpeg_writer.py", line 223, in ffmpeg_write_video
writer.write_frame(frame)
File "/usr/local/lib/python2.7/dist-packages/moviepy/video/io/ffmpeg_writer.py", line 186, in write_frame
raise IOError(error)
IOError: [Errno 32] Broken pipe

MoviePy error: FFMPEG encountered the following error while writing file composition.mp4:

Unrecognized option 'preset'
Failed to set value 'medium' for option 'preset'

So far I got from Google that it meight be a problem saving a temp file and that I should pass a path to it. But According to Movipy docs write_videofile has not parameter for that.

This is a new one for me! Are you still using the same code above, and it produces this error?

what's the ffmpeg version ?

Jup, same code. ffmpeg returrns:
ffmpeg version 0.8.6-6:0.8.6-1ubuntu2, Copyright (c) 2000-2013 the Libav developers
built on Mar 30 2013 22:20:06 with gcc 4.7.2

If I enter ffmpeg -preset medium it give the same error. It is latest version from the repos.

Your version of ffmpeg is 4 years old, you should try installing a more recent one (it's pretty easy to do, you download a binary and copy it in usr/bin).

Let me try it. For testing I outcommented line 104 of moviepy/video/io/ffmpeg_writer.py to get rid of the preset option. And tada, it works. So may be the old version from the repo might be so old that it doesn't have this option.

Works perfectly! Now have ffmpeg 7:3.2.2. Thanks for all. Do we something like a thumbs-up button on git?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

skizzy picture skizzy  路  3Comments

arianaa30 picture arianaa30  路  4Comments

LaoYuanPython picture LaoYuanPython  路  3Comments

Deng-deng-deng-deng picture Deng-deng-deng-deng  路  3Comments

cquintini picture cquintini  路  4Comments