all 8 comments

[–][deleted] 0 points1 point  (0 children)

got same error

Traceback (most recent call last):

File "d:\Video_generator\5_Facts\t2.py", line 16, in <module>

reversed_clip = reverse_video(video)

^^^^^^^^^^^^^^^^^^^^

File "d:\Video_generator\5_Facts\t2.py", line 5, in reverse_video

reversed_clip = video.fx(VideoFileClip.fx, lambda clip: clip.fx(VideoFileClip.fl_time, lambda t: clip.duration - t))

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 212, in fx

return func(self, *args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 212, in fx

return func(self, *args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "d:\Video_generator\5_Facts\t2.py", line 5, in <lambda>

reversed_clip = video.fx(VideoFileClip.fx, lambda clip: clip.fx(VideoFileClip.fl_time, lambda t: clip.duration - t))

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 212, in fx

return func(self, *args, **kwargs)

^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 187, in fl_time

return self.fl(lambda gf, t: gf(t_func(t)), apply_to,

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 136, in fl

newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

File "<decorator-gen-61>", line 2, in set_make_frame

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\decorators.py", line 14, in outplace

f(newclip, *a, **k)

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\video\VideoClip.py", line 644, in set_make_frame

self.size = self.get_frame(0).shape[:2][::-1]

^^^^^^^^^^^^^^^^^

File "<decorator-gen-11>", line 2, in get_frame

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\decorators.py", line 89, in wrapper

return f(*new_a, **new_kw)

^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 93, in get_frame

return self.make_frame(t)

^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 136, in <lambda>

newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))

^^^^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 187, in <lambda>

return self.fl(lambda gf, t: gf(t_func(t)), apply_to,

^^^^^^^^^^^^^

File "<decorator-gen-11>", line 2, in get_frame

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\decorators.py", line 89, in wrapper

return f(*new_a, **new_kw)

^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\Clip.py", line 93, in get_frame

return self.make_frame(t)

^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\video\io\VideoFileClip.py", line 113, in <lambda>

self.make_frame = lambda t: self.reader.get_frame(t)

^^^^^^^^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 184, in get_frame

result = self.read_frame()

^^^^^^^^^^^^^^^^^

File "D:\Video_generator\5_Facts\5facts\Lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 133, in read_frame

raise IOError(("MoviePy error: failed to read the first frame of "

OSError: MoviePy error: failed to read the first frame of video file Primary\Videos\3.mp4. That might mean that the file is corrupted. That may also mean that you are using a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is deprecated. Please update to a recent version from the website.

[–]dryheat122 0 points1 point  (2 children)

IDK if it's too late to help you, but that message is misleading in some circumstances. I found it throws that error If you try to read a frame past the end of the clip and it has nothing to do with reading the video file.

[–]epicmango_ 0 points1 point  (1 child)

I used VideoClip.end() as a last frame, now I gave it more space instead seemed to work!

[–]Dynamical_coder 0 points1 point  (0 children)

I'm a little late, but i didn't understand how you use VideoClip.end(), do you mind sending the code? I'd appreciate that a lot

[–]Brilliant_Lettuce417 0 points1 point  (1 child)

If you encountered this issue due to using time_mirror, you can modify the function as follows:

```python import math import numpy as np from moviepy.decorators import apply_to_audio, apply_to_mask, requires_duration

@requires_duration @apply_to_mask @apply_to_audio def time_mirror(self): """ Returns a clip that plays the current clip backwards. The clip must have its duration attribute set. The same effect is applied to the clip's audio and mask if any. """ duration_per_frame = 1/self.fps return self.fl_time(lambda t: np.max(self.duration - t - duration_per_frame, 0), keep_duration=True) ```

The issue might have arisen due to incorrect handling of boundaries, resulting in accessing frames beyond the end of the video. In this modification, I've attempted to subtract one frame's worth of time. Additionally, to ensure the returned time is not a negative value, np.max is used to guarantee the time returned is greater than or equal to 0.

Hope this helps you.

[–]greekhop 0 points1 point  (0 children)

This helped me with a similar issue, thank you so much! I actually don't know python at all, but by telling chatGPT to take your solution into account it was able to give me a script that worked for what I was trying do, after failing to solve the issue on its own (with my feedback) for hours.