[Python] Exception has occurred: OSError MoviePy error: failed to read the first frame of...

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    WHAT I'M DOING:

    Looping a video for a certain amount of time.

    However, I'm getting the following error (The file is not corrupt):

    Exception has occurred: OSError
    MoviePy error: failed to read the first frame of video file Pexels Videos 1292738.mp4. That might mean that the file is corrupted.


    at the commented line in my code:

    chdir(r'C:\Users\jack_l\Downloads\makeAVideo\stock')
    myStock = next(walk(r'C:\Users\jack_l\Downloads\makeAVideo\stock'), (None, None, []))[2]
    stockFile = VideoFileClip(str(myStock[0]), target_resolution=(1080, 1920), audio=False)
    stockFile = stockFile.loop(duration = 300)
    stockFile = stockFile.set_fps(30)
    chdir(r'C:\Users\jack_l\Downloads\makeAVideo')
    stockFile.write_videofile('theVideo.mp4') # this line


    Does anyone know what's going wrong? Any help is greatly appreciated, thank you.

    THE FILE I'M USING:

    https://drive.google.com/drive/folders/1n8ReLmPj8cIUi6og_GgmlRoumCMB7zIL?usp=sharing

    FULL ERROR:

    Traceback (most recent call last):
    File "c:\Users\jack_l\Downloads\makeVideos.py", line 40, in <module>
    stockFile.write_videofile('theVideo.mp4')
    File "<decorator-gen-55>", line 2, in write_videofile
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\decorators.py", line 54, in requires_duration
    return f(clip, *a, **k)
    File "<decorator-gen-54>", line 2, in write_videofile
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\decorators.py", line 135, in use_clip_fps_by_default
    return f(clip, *new_a, **new_kw)
    File "<decorator-gen-53>", line 2, in write_videofile
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\decorators.py", line 22, in convert_masks_to_RGB
    return f(clip, *a, **k)
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\video\VideoClip.py", line 300,
    in write_videofile
    ffmpeg_write_video(self, filename, fps, codec,
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\video\io\ffmpeg_writer.py", line 220, in ffmpeg_write_video
    for t,frame in clip.iter_frames(logger=logger, with_times=True,
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\Clip.py", line 472, in iter_frames
    frame = self.get_frame(t)
    File "<decorator-gen-11>", line 2, in get_frame
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\Clip.py", line 93, in get_frame return self.make_frame(t)
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\Clip.py", line 136, in <lambda> newclip = self.set_make_frame(lambda t: fun(self.get_frame, t))
    File "c:\users\jack_l\appdata\local\programs\python\python310\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 "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\decorators.py", line 89, in wrapper
    return f(*new_a, **new_kw)
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\Clip.py", line 93, in get_frame return self.make_frame(t)
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 113, in <lambda>
    self.make_frame = lambda t: self.reader.get_frame(t)
    File "c:\users\jack_l\appdata\local\programs\python\python310\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 184, in get_frame
    result = self.read_frame()
    File "c:\users\jack_l\appdata\local\programs\python\python310\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 Pexels Videos 1292738.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.

    Continue reading...

Compartilhe esta Página