Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'get_frame' when calling write_videofile #2198

Open
Ervin66 opened this issue Jun 15, 2024 · 1 comment
Labels
bug Issues that report (apparent) bugs.

Comments

@Ervin66
Copy link

Ervin66 commented Jun 15, 2024

I encountered an AttributeError when attempting to write a video file using write_videofile in MoviePy. The error message indicates that a NoneType object has no attribute get_frame.

Full traceback:

AttributeError                            Traceback (most recent call last)
Cell In[8], line 1
----> 1 combined_vid.write_videofile("test.mp4")

File <decorator-gen-70>:2, in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, temp_audiofile_path, rewrite_audio, remove_temp, write_logfile, threads, ffmpeg_params, logger, pix_fmt)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:56, in requires_duration(f, clip, *a, **k)
     54     raise ValueError("Attribute 'duration' not set")
     55 else:
---> 56     return f(clip, *a, **k)

File <decorator-gen-69>:2, in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, temp_audiofile_path, rewrite_audio, remove_temp, write_logfile, threads, ffmpeg_params, logger, pix_fmt)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:135, in use_clip_fps_by_default(f, clip, *a, **k)
    132 new_a = [fun(arg) if (name == "fps") else arg for (arg, name) in zip(a, names)]
    133 new_kw = {k: fun(v) if k == "fps" else v for (k, v) in k.items()}
--> 135 return f(clip, *new_a, **new_kw)

File <decorator-gen-68>:2, in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, temp_audiofile_path, rewrite_audio, remove_temp, write_logfile, threads, ffmpeg_params, logger, pix_fmt)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:24, in convert_masks_to_RGB(f, clip, *a, **k)
     22 if clip.ismask:
     23     clip = clip.to_RGB()
---> 24 return f(clip, *a, **k)

File <decorator-gen-67>:2, in write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, temp_audiofile_path, rewrite_audio, remove_temp, write_logfile, threads, ffmpeg_params, logger, pix_fmt)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:89, in preprocess_args.<locals>.wrapper(f, *a, **kw)
     84 new_a = [
     85     fun(arg) if (name in varnames) and (arg is not None) else arg
     86     for (arg, name) in zip(a, names)
     87 ]
     88 new_kw = {k: fun(v) if k in varnames else v for (k, v) in kw.items()}
---> 89 return f(*new_a, **new_kw)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\video\VideoClip.py:332, in VideoClip.write_videofile(self, filename, fps, codec, bitrate, audio, audio_fps, preset, audio_nbytes, audio_codec, audio_bitrate, audio_bufsize, temp_audiofile, temp_audiofile_path, rewrite_audio, remove_temp, write_logfile, threads, ffmpeg_params, logger, pix_fmt)
    330 logger(message="Moviepy - Building video %s." % filename)
    331 if make_audio:
--> 332     self.audio.write_audiofile(
    333         audiofile,
    334         audio_fps,
    335         audio_nbytes,
    336         audio_bufsize,
    337         audio_codec,
    338         bitrate=audio_bitrate,
    339         write_logfile=write_logfile,
    340         logger=logger,
    341     )
    343 ffmpeg_write_video(
    344     self,
    345     filename,
   (...)
    355     pix_fmt=pix_fmt,
    356 )
    358 if remove_temp and make_audio:

File <decorator-gen-102>:2, in write_audiofile(self, filename, fps, nbytes, buffersize, codec, bitrate, ffmpeg_params, write_logfile, logger)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:56, in requires_duration(f, clip, *a, **k)
     54     raise ValueError("Attribute 'duration' not set")
     55 else:
---> 56     return f(clip, *a, **k)

File <decorator-gen-101>:2, in write_audiofile(self, filename, fps, nbytes, buffersize, codec, bitrate, ffmpeg_params, write_logfile, logger)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:89, in preprocess_args.<locals>.wrapper(f, *a, **kw)
     84 new_a = [
     85     fun(arg) if (name in varnames) and (arg is not None) else arg
     86     for (arg, name) in zip(a, names)
     87 ]
     88 new_kw = {k: fun(v) if k in varnames else v for (k, v) in kw.items()}
---> 89 return f(*new_a, **new_kw)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\audio\AudioClip.py:230, in AudioClip.write_audiofile(self, filename, fps, nbytes, buffersize, codec, bitrate, ffmpeg_params, write_logfile, logger)
    223     except KeyError:
    224         raise ValueError(
    225             "MoviePy couldn't find the codec associated "
    226             "with the filename. Provide the 'codec' "
    227             "parameter in write_audiofile."
    228         )
--> 230 return ffmpeg_audiowrite(
    231     self,
    232     filename,
    233     fps,
    234     nbytes,
    235     buffersize,
    236     codec=codec,
    237     bitrate=bitrate,
    238     write_logfile=write_logfile,
    239     ffmpeg_params=ffmpeg_params,
    240     logger=logger,
    241 )

File <decorator-gen-97>:2, in ffmpeg_audiowrite(clip, filename, fps, nbytes, buffersize, codec, bitrate, write_logfile, ffmpeg_params, logger)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:56, in requires_duration(f, clip, *a, **k)
     54     raise ValueError("Attribute 'duration' not set")
     55 else:
---> 56     return f(clip, *a, **k)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\audio\io\ffmpeg_audiowriter.py:204, in ffmpeg_audiowrite(clip, filename, fps, nbytes, buffersize, codec, bitrate, write_logfile, ffmpeg_params, logger)
    192 logger(message="MoviePy - Writing audio in %s" % filename)
    193 writer = FFMPEG_AudioWriter(
    194     filename,
    195     fps,
   (...)
    201     ffmpeg_params=ffmpeg_params,
    202 )
--> 204 for chunk in clip.iter_chunks(
    205     chunksize=buffersize, quantize=True, nbytes=nbytes, fps=fps, logger=logger
    206 ):
    207     writer.write_frames(chunk)
    209 writer.close()

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\audio\AudioClip.py:90, in AudioClip.iter_chunks(self, chunksize, chunk_duration, fps, quantize, nbytes, logger)
     88 assert size <= chunksize
     89 tt = (1.0 / fps) * np.arange(pospos[i], pospos[i + 1])
---> 90 yield self.to_soundarray(
     91     tt, nbytes=nbytes, quantize=quantize, fps=fps, buffersize=chunksize
     92 )

File <decorator-gen-99>:2, in to_soundarray(self, tt, fps, quantize, nbytes, buffersize)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:56, in requires_duration(f, clip, *a, **k)
     54     raise ValueError("Attribute 'duration' not set")
     55 else:
---> 56     return f(clip, *a, **k)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\audio\AudioClip.py:138, in AudioClip.to_soundarray(self, tt, fps, quantize, nbytes, buffersize)
    128 """
    129 elif len(tt)> 1.5*buffersize:
    130     nchunks = int(len(tt)/buffersize+1)
   (...)
    134                       for ttc in tt_chunks])
    135 """
    136 # print tt.max() - tt.min(), tt.min(), tt.max()
--> 138 snd_array = self.get_frame(tt)
    140 if quantize:
    141     snd_array = np.maximum(-0.99, np.minimum(0.99, snd_array))

File <decorator-gen-28>:2, in get_frame(self, t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:89, in preprocess_args.<locals>.wrapper(f, *a, **kw)
     84 new_a = [
     85     fun(arg) if (name in varnames) and (arg is not None) else arg
     86     for (arg, name) in zip(a, names)
     87 ]
     88 new_kw = {k: fun(v) if k in varnames else v for (k, v) in kw.items()}
---> 89 return f(*new_a, **new_kw)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:98, in Clip.get_frame(self, t)
     95         return frame
     96 else:
     97     # print(t)
---> 98     return self.make_frame(t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\audio\AudioClip.py:320, in CompositeAudioClip.__init__.<locals>.make_frame(t)
    316 def make_frame(t):
    318     played_parts = [c.is_playing(t) for c in self.clips]
--> 320     sounds = [
    321         c.get_frame(t - c.start) * np.array([part]).T
    322         for c, part in zip(self.clips, played_parts)
    323         if (part is not False)
    324     ]
    326     if isinstance(t, np.ndarray):
    327         zero = np.zeros((len(t), self.nchannels))

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\audio\AudioClip.py:321, in <listcomp>(.0)
    316 def make_frame(t):
    318     played_parts = [c.is_playing(t) for c in self.clips]
    320     sounds = [
--> 321         c.get_frame(t - c.start) * np.array([part]).T
    322         for c, part in zip(self.clips, played_parts)
    323         if (part is not False)
    324     ]
    326     if isinstance(t, np.ndarray):
    327         zero = np.zeros((len(t), self.nchannels))

File <decorator-gen-28>:2, in get_frame(self, t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:89, in preprocess_args.<locals>.wrapper(f, *a, **kw)
     84 new_a = [
     85     fun(arg) if (name in varnames) and (arg is not None) else arg
     86     for (arg, name) in zip(a, names)
     87 ]
     88 new_kw = {k: fun(v) if k in varnames else v for (k, v) in kw.items()}
---> 89 return f(*new_a, **new_kw)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:98, in Clip.get_frame(self, t)
     95         return frame
     96 else:
     97     # print(t)
---> 98     return self.make_frame(t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:141, in Clip.fl.<locals>.<lambda>(t)
    138     apply_to = []
    140 # mf = copy(self.make_frame)
--> 141 newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
    143 if not keep_duration:
    144     newclip.duration = None

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:193, in Clip.fl_time.<locals>.<lambda>(gf, t)
    189 if apply_to is None:
    190     apply_to = []
    192 return self.fl(
--> 193     lambda gf, t: gf(t_func(t)), apply_to, keep_duration=keep_duration
    194 )

File <decorator-gen-28>:2, in get_frame(self, t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:89, in preprocess_args.<locals>.wrapper(f, *a, **kw)
     84 new_a = [
     85     fun(arg) if (name in varnames) and (arg is not None) else arg
     86     for (arg, name) in zip(a, names)
     87 ]
     88 new_kw = {k: fun(v) if k in varnames else v for (k, v) in kw.items()}
---> 89 return f(*new_a, **new_kw)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:98, in Clip.get_frame(self, t)
     95         return frame
     96 else:
     97     # print(t)
---> 98     return self.make_frame(t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:141, in Clip.fl.<locals>.<lambda>(t)
    138     apply_to = []
    140 # mf = copy(self.make_frame)
--> 141 newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
    143 if not keep_duration:
    144     newclip.duration = None

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:193, in Clip.fl_time.<locals>.<lambda>(gf, t)
    189 if apply_to is None:
    190     apply_to = []
    192 return self.fl(
--> 193     lambda gf, t: gf(t_func(t)), apply_to, keep_duration=keep_duration
    194 )

File <decorator-gen-28>:2, in get_frame(self, t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\decorators.py:89, in preprocess_args.<locals>.wrapper(f, *a, **kw)
     84 new_a = [
     85     fun(arg) if (name in varnames) and (arg is not None) else arg
     86     for (arg, name) in zip(a, names)
     87 ]
     88 new_kw = {k: fun(v) if k in varnames else v for (k, v) in kw.items()}
---> 89 return f(*new_a, **new_kw)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\Clip.py:98, in Clip.get_frame(self, t)
     95         return frame
     96 else:
     97     # print(t)
---> 98     return self.make_frame(t)

File c:\Users\user\miniconda3\envs\yt-dev\Lib\site-packages\moviepy\audio\io\AudioFileClip.py:88, in AudioFileClip.__init__.<locals>.<lambda>(t)
     85 self.buffersize = self.reader.buffersize
     86 self.filename = filename
---> 88 self.make_frame = lambda t: self.reader.get_frame(t)
     89 self.nchannels = self.reader.nchannels

AttributeError: 'NoneType' object has no attribute 'get_frame'

Expected Behavior

expected to write a mp4 file

Actual Behavior

attribute error

Steps to Reproduce the Problem

Specifications

  • Python Version: 3.11.9
  • MoviePy Version: 1.0.3
  • Platform Name: windows
  • Platform Version: 10
@Ervin66 Ervin66 added the bug Issues that report (apparent) bugs. label Jun 15, 2024
@harroopsra
Copy link

Can you post your code so we can try and see where the problem might lie? It's a little hard to give a catchall answer, some more context would be good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that report (apparent) bugs.
Projects
None yet
Development

No branches or pull requests

2 participants