0

I am trying to reverse a video using MoviePy. My code is as under: -

from moviepy.editor import VideoFileClip
from moviepy.video.fx.all import time_mirror

clip = VideoFileClip("udit.mp4")

clip = clip.fx(time_mirror)

clip.write_videofile("reversed.mp4")

But, when I run it I get the following error:-

Traceback (most recent call last):
  File "/Users/uditvashisht/projects/experiments/script.py", line 6, in <module>
    clip = clip.fx(time_mirror)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/Clip.py", line 212, in fx
    return func(self, *args, **kwargs)
  File "<decorator-gen-89>", line 2, in time_mirror
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
  File "<decorator-gen-88>", line 2, in time_mirror
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/decorators.py", line 29, in apply_to_mask
    newclip = f(clip, *a, **k)
  File "<decorator-gen-87>", line 2, in time_mirror
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/decorators.py", line 41, in apply_to_audio
    newclip = f(clip, *a, **k)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/video/fx/time_mirror.py", line 13, in time_mirror
    return self.fl_time(lambda t: self.duration - t, keep_duration=True)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/Clip.py", line 187, in fl_time
    return self.fl(lambda gf, t: gf(t_func(t)), apply_to,
  File "/opt/homebrew/lib/python3.9/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 "/opt/homebrew/lib/python3.9/site-packages/moviepy/decorators.py", line 14, in outplace
    f(newclip, *a, **k)
  File "/opt/homebrew/lib/python3.9/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 "/opt/homebrew/lib/python3.9/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/Clip.py", line 136, in <lambda>
    newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
  File "/opt/homebrew/lib/python3.9/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 "/opt/homebrew/lib/python3.9/site-packages/moviepy/decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/Clip.py", line 93, in get_frame
    return self.make_frame(t)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/video/io/VideoFileClip.py", line 113, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
  File "/opt/homebrew/lib/python3.9/site-packages/moviepy/video/io/ffmpeg_reader.py", line 184, in get_frame
    result = self.read_frame()
  File "/opt/homebrew/lib/python3.9/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 udit.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

I have tried the code on both Mac and Windows PC. The other functionality of MoviePy works fine, but I am not able to reverse the video. Both of my systems have ImageMagick and FFMPEG installed.

  • Which specific codecs does it use? Do you have them installed? – tripleee Jul 14 '22 at 08:03
  • @tripleee If I correctly understand your question, I can play the video, which I am trying to reverse. So I assume my machine has the necessary codecs. – Udit Hari Vashisht Jul 14 '22 at 08:46
  • Actually, ffmpeg binary uses its own codecs, and it depends on builds. Try in command prompt (or with `os.system` in Python) run `ffmpeg -i udit.mp4` and post what it prints out. – kesh Jul 14 '22 at 14:32

0 Answers0