Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "TypeError: must be real number, not NoneType" whenever trying to run write_videofile to a clip in moviepy

Example code:

from moviepy.editor import *
clip = VideoFileClip('video.mp4')
clip.write_videofile('video2.mp4', fps=30)

After showing the following messages, showing that the video is being built and written,

Moviepy - Building video video2.mp4.
Moviepy - Writing video video2.mp4

The following error message occurs:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\Anaconda3\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "C:\Users\User\Anaconda3\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
  File "C:\Users\User\Anaconda3\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
  File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\video\VideoClip.py", line 300, in write_videofile
    ffmpeg_write_video(self, filename, fps, codec,
  File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 213, in ffmpeg_write_video
    with FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec,
  File "C:\Users\User\Anaconda3\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 88, in __init__
    '-r', '%.02f' % fps,
TypeError: must be real number, not NoneType

This occurs whenever I try to perform write_videofile to any kinds of clip in moviepy. It is strange since the exact same code worked for me yesterday, but suddenly not anymore today. Are there any suggestions what the cause is and how to resolve this?

like image 330
Sato Avatar asked Mar 02 '23 13:03

Sato


2 Answers

Try upgrading your moviepy package

pip install moviepy --upgrade

I was facing the same issue with 1.0.0. Upgrading to 1.0.3 fixed that issue.

like image 58
Ramkumar Singh Avatar answered Mar 07 '23 07:03

Ramkumar Singh


I just had the same problem (even with version 1.0.3 of moviepy) while trying to display the video clip in a Jupyter notebook using clip.ipython_display.

In my case, the problem was caused by the FFmpeg version detected by moviepy which was ffmpeg-imageio (whatever that is).

As described on the installation page of moviepy, you can basically do two things:

  • Pass the location of the FFmpeg binary you want to use using the FFMPEG_BINARY environment variable.
  • Edit the file config_defaults.py and set the variable to the location of the binary there.

In both cases, you need to restart the process/kernel for the effects to take place. In my case, I found the config_defaults.py inside my virtual env folder (on Linux) at:

<project dir>/.venv/lib/python3.7/site-packages/moviepy/config_defaults.py
like image 45
Alex R Avatar answered Mar 07 '23 07:03

Alex R