moviepy
moviepy copied to clipboard
"TypeError: must be a real number, not NoneType" when trying to use "write_videofile" on any platform other than Google Colab or my computer
Due to limitations of Google Colab resources, I am trying to use MoviePy on other platforms. The latest platform I tried was a free account on DeepNote. However, when executing the code:
from moviepy.editor import *
text_clip = TextClip("Hello world!", fontsize=70, color='white')
bg_clip = ColorClip(size=(720, 480), color='black')
final_clip = CompositeVideoClip([bg_clip, text_clip]).set_duration(10)
final_clip.write_videofile("texto.mp4", fps=30)
The following errors happen:
Moviepy - Building video texto.mp4.
Moviepy - Writing video texto.mp4
TypeError: must be real number, not NoneType
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In [1], line 13
10 final_clip = CompositeVideoClip([bg_clip, text_clip]).set_duration(10)
12 # Salvando o resultado
---> 13 final_clip.write_videofile("texto.mp4", fps=30)
File /shared-libs/python3.10/py-core/lib/python3.10/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
File ~/venv/lib/python3.10/site-packages/moviepy/decorators.py:54, in requires_duration(f, clip, *a, **k)
52 raise ValueError("Attribute 'duration' not set")
53 else:
---> 54 return f(clip, *a, **k)
File /shared-libs/python3.10/py-core/lib/python3.10/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
File ~/venv/lib/python3.10/site-packages/moviepy/decorators.py:135, in use_clip_fps_by_default(f, clip, *a, **k)
130 new_a = [fun(arg) if (name=='fps') else arg
131 for (arg, name) in zip(a, names)]
132 new_kw = {k: fun(v) if k=='fps' else v
133 for (k,v) in k.items()}
--> 135 return f(clip, *new_a, **new_kw)
File /shared-libs/python3.10/py-core/lib/python3.10/site-packages/decorator.py:232, in decorate.<locals>.fun(*args, **kw)
230 if not kwsyntax:
231 args, kw = fix(args, kw, sig)
--> 232 return caller(func, *(extras + args), **kw)
File ~/venv/lib/python3.10/site-packages/moviepy/decorators.py:22, in convert_masks_to_RGB(f, clip, *a, **k)
20 if clip.ismask:
21 clip = clip.to_RGB()
---> 22 return f(clip, *a, **k)
File ~/venv/lib/python3.10/site-packages/moviepy/video/VideoClip.py:300, in VideoClip.write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, rewrite_audio, remove_temp, write_logfile, verbose, threads, ffmpeg_params, logger)
292 if make_audio:
293 self.audio.write_audiofile(audiofile, audio_fps,
294 audio_nbytes, audio_bufsize,
295 audio_codec, bitrate=audio_bitrate,
296 write_logfile=write_logfile,
297 verbose=verbose,
298 logger=logger)
--> 300 ffmpeg_write_video(self, filename, fps, codec,
301 bitrate=bitrate,
302 preset=preset,
303 write_logfile=write_logfile,
304 audiofile=audiofile,
305 verbose=verbose, threads=threads,
306 ffmpeg_params=ffmpeg_params,
307 logger=logger)
309 if remove_temp and make_audio:
310 if os.path.exists(audiofile):
File ~/venv/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_writer.py:213, in ffmpeg_write_video(clip, filename, fps, codec, bitrate, preset, withmask, write_logfile, audiofile, verbose, threads, ffmpeg_params, logger)
211 logfile = None
212 logger(message='Moviepy - Writing video %s\n' % filename)
--> 213 with FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec,
214 preset=preset, bitrate=bitrate, logfile=logfile,
215 audiofile=audiofile, threads=threads,
216 ffmpeg_params=ffmpeg_params) as writer:
218 nframes = int(clip.duration*fps)
220 for t,frame in clip.iter_frames(logger=logger, with_times=True,
221 fps=fps, dtype="uint8"):
File ~/venv/lib/python3.10/site-packages/moviepy/video/io/ffmpeg_writer.py:88, in FFMPEG_VideoWriter.__init__(self, filename, size, fps, codec, audiofile, preset, bitrate, withmask, logfile, threads, ffmpeg_params)
77 self.ext = self.filename.split(".")[-1]
79 # order is important
80 cmd = [
81 get_setting("FFMPEG_BINARY"),
82 '-y',
83 '-loglevel', 'error' if logfile == sp.PIPE else 'info',
84 '-f', 'rawvideo',
85 '-vcodec', 'rawvideo',
86 '-s', '%dx%d' % (size[0], size[1]),
87 '-pix_fmt', 'rgba' if withmask else 'rgb24',
---> 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
To avoid other errors that I discovered earlier I do:
!sudo apt-get update
!sudo apt install -y imagemagick
!sudo sed -i 's/none/read,write/g'> /etc/ImageMagick-6/policy.xml
!export 'IMAGEMAGICK_BINARY'='/usr/bin/convert'
!pip install moviepy
I just want to use MoviePy to generate a video with text appearing on the screen using Deepnote, but at some point in the code, the variable fps
becomes None
, resulting in an error in the operation ‘%.02f’ % fps
.
Master seems to have this issue solved https://github.com/Zulko/moviepy/issues/1990
Please always include your specs like we ask for in our issue templates – MoviePy version, platform used etc. – to help pinpoint what causes your problem, thanks.
@keikoro I can reproduce this bug report with the precise (fairly reproducible thanks to nixos) instruction I provided in https://github.com/Zulko/moviepy/issues/1990
I have solved this problem through the following command
pip uninstall moviepy decorator pip install moviepy
Has anybody been able to crack it, It works fine on my local but using a docker file it shows error
FROM python:3.8
RUN apt-get update && apt-get install texlive-latex-extra -y
RUN apt-get update && apt-get install -y ffmpeg && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install libportaudio2 -y && \
apt-get install libpango1.0-dev -y
RUN pip3 install moviepy
COPY requirements.txt /reels-gen-service/
WORKDIR /reels-gen-service
RUN pip3 install -r requirements.txt
ADD . /reels-gen-service/
CMD [ "python3", "flask_app.py" ]
Everything works fine till,
Moviepy - Building video ./arithmeticpropexplanation.mp4.
MoviePy - Writing audio in arithmeticpropexplanationTEMP_MPY_wvf_snd.mp3
FFMPEG_VideoWriter(filename, clip.size, fps, codec = codec,\n File \"/usr/local/lib/python3.8/site-packages/moviepy/video/io/ffmpeg_writer.py\", line 88, in __init__\n '-r', '%.02f' % fps,\nTypeError: must be real number, not NoneType"}
@Fujiwara16 I would try to install the github version from the master branch.
There is a simple solution to this problem (restart kernel): https://github.com/msieg/deep-music-visualizer/issues/17#issuecomment-1376279809
I created two different Conda environments on two separate computers. One of these environments, utilizing Python 3.10, works without any problems. However, the other environment, which was created similarly but uses Python 3.11, presented this specific issue.
Solution Implemented:
In order to resolve this issue swiftly, I made a modification to the VideoClip.py file within the MoviePy library. Specifically, I added the code below to the write_video_file method. The code ensures that if the fps is not explicitly defined, it defaults to using the clip's fps attribute, which I believe is very similar (though not identical) to the behavior provided by the @use_clip_fps_by_default decorator.
if fps is None:
fps = self.fps
Suggestion:
I would like to suggest considering the removal of the @use_clip_fps_by_default decorator from the write_video_file method. The corresponding code of the decorator would then be copied into the body of the method. This change seems to eliminate the issue, which appears to be affecting so many users. By removing this decorator, you could potentially resolve this pervasive bug that frustrates so many users.
I created two different Conda environments on two separate computers. One of these environments, utilizing Python 3.10, works without any problems. However, the other environment, which was created similarly but uses Python 3.11, presented this specific issue.
Solution Implemented:
In order to resolve this issue swiftly, I made a modification to the VideoClip.py file within the MoviePy library. Specifically, I added the code below to the write_video_file method. The code ensures that if the fps is not explicitly defined, it defaults to using the clip's fps attribute, which I believe is very similar (though not identical) to the behavior provided by the @use_clip_fps_by_default decorator.
if fps is None: fps = self.fps
Suggestion:
I would like to suggest considering the removal of the @use_clip_fps_by_default decorator from the write_video_file method. The corresponding code of the decorator would then be copied into the body of the method. This change seems to eliminate the issue, which appears to be affecting so many users. By removing this decorator, you could potentially resolve this pervasive bug that frustrates so many users.
I have tried every method almost. It seems there is only one way I can walk, and fortunately it works ultimately. But I think it's not the best way to solve the problem, It's a very not elegant solution, I hope there will be a better solution in the future.
I have solved this problem through the following command
pip uninstall moviepy decorator pip install moviepy
Can you please insert a newline between the uninstall and the install? I copied yours and removed my pip
. I had to repair my env with conda install -f pip
I created two different Conda environments on two separate computers. One of these environments, utilizing Python 3.10, works without any problems. However, the other environment, which was created similarly but uses Python 3.11, presented this specific issue.
Solution Implemented:
In order to resolve this issue swiftly, I made a modification to the VideoClip.py file within the MoviePy library. Specifically, I added the code below to the write_video_file method. The code ensures that if the fps is not explicitly defined, it defaults to using the clip's fps attribute, which I believe is very similar (though not identical) to the behavior provided by the @use_clip_fps_by_default decorator.
if fps is None: fps = self.fps
Suggestion:
I would like to suggest considering the removal of the @use_clip_fps_by_default decorator from the write_video_file method. The corresponding code of the decorator would then be copied into the body of the method. This change seems to eliminate the issue, which appears to be affecting so many users. By removing this decorator, you could potentially resolve this pervasive bug that frustrates so many users.
Thanks! It really works in my env
I also have same problem.final I solve this question by Downgrade decorator to version 4.0.2
There is a simple solution to this problem (restart kernel): msieg/deep-music-visualizer#17 (comment)
Thanks!It works for me.
I have solved this problem through the following command
pip uninstall moviepy decorator pip install moviepy
Just in case: $ pip uninstall moviepy decorator $ pip install moviepy