13

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?

Sato
  • 1,013
  • 1
  • 12
  • 27

15 Answers15

25

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.

Ramkumar Singh
  • 2,240
  • 4
  • 15
  • 18
6

My problem presented as:

---> 88     '-r', '%.02f' % fps,
     89     '-an', '-i', '-'
     90 ]
     91 if audiofile is not None:
     92     cmd.extend([
     93         '-i', audiofile,
     94         '-acodec', 'copy'
     95     ])

TypeError: must be real number, not NoneType

It would save the MP3 file, but failed when writing the MP4 file.

I fixed this problem with:

pip install ffmpeg --upgrade
BigDict
  • 61
  • 1
  • 2
5

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
Alex R
  • 3,139
  • 1
  • 18
  • 28
2

I had the same exact problem, even with 1.0.3. In my case, I got it to work by reinstalling ffmpeg over Homebrew with brew reinstall ffmpeg.

  • Confirm solution is working (MacOS 10.15.5 Catalina), had the same issue. `pip install moviepy --upgrade` did not solve my problem. – Medomatto Sep 22 '21 at 21:59
2

If upgrade your moviepy package is not work for you

Try downgrade the decorator package

pip install --upgrade decorator==4.4.2

yukine7
  • 21
  • 1
  • I had to try a few different decorator versions, I ended up settling on the earliest one allowed by moviepy 1.0.3 which was decorator 4.0.2 – AtomLaurent Jul 25 '23 at 04:20
0

Had the same problem on mac.

brew reinstall ffmpeg 

worked for me.

Maiia Bocharova
  • 149
  • 1
  • 7
0

It sounds silly, but Python code file was in folder with long path. Moved file to shorter one and it worked.

MrCarrots
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 03 '23 at 01:37
0

Windows 11 version 22h2, x64 system, Ryzen 7 here is some information on my conifguration

  • jupyter : 1.0
  • jupyterlab: 3.5.3
  • python: 3.9.16
  • moviepy: 1.0.3
  • ffmpeg: 1.4
  • pygame: 2.3
  • decorator: 4.4.2

running through jupyterlab

in order to not get the "TypeError must be a real number" error, I had to pip install these specific specific versions of the packages.

  • pygame not installed: error
  • ffmpeg not installed: error
  • pygame not installed: error
  • decorator older or newer than 4.4.2: error
  • python 3.10 : error
0

in my case

pip uninstall ffmpeg moviepy

pip install moviepy

NickygenN
  • 1
  • 1
  • Hello, please don't just submit code/commands in your answer(s), add some details as to why you think this is the optimal solution – Destroy666 May 23 '23 at 13:04
0

This problem could be related to your Python version, as I had the same issue with Python 3.6.13, Moviepy 1.0.3, and Pygame 2.4.0. However, when I switched to Python 3.8.16 and reinstalled Moviepy and Pygame with the same versions, it worked well.

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '23 at 16:03
0

I had this error using Python 3.10, and it appears to be fixed by downgrading to Python 3.9.

(Using MoviePy 1.0.3)

BFD
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 28 '23 at 15:53
0

For me the problem was not with MoviePy or FFMPEG, but with the decorator version. Only after downgrading it to 4.0.2 I could make it to work.

Try downgrade the decorator package

pip install --upgrade decorator==4.0.2
AlexSC
  • 1,823
  • 3
  • 28
  • 54
-1

I just replaced the argument in the function: (file ffmpeg_writer.py for me it in C:\Anaconda3\Lib\site-packages\moviepy\video\io)

def ffmpeg_write_video(clip, filename, fps, codec="libx264", bitrate=None, ...

with:

def ffmpeg_write_video(clip, filename, fps, codec="libx264", bitrate=0.0, ...
-1

for me installing pygame corrected the problem

pip install pygame

as stated here : https://zulko.github.io/moviepy/install.html

-1

try: fps=final_clip.fps

from moviepy.editor import *
clip = VideoFileClip('video.mp4')
clip.write_videofile('video2.mp4', fps=final_clip.fps)
PemaGrg
  • 722
  • 7
  • 5