[Python] Getting error "OSError: MoviePy error: failed to read the first frame" only on...

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    So I have an issue with moviepy, specifically VideoFileClip. When I run my code here's the error:

    {'video_found': True, 'audio_found': True, 'metadata': {'major_brand': 'mp42', 'minor_version': '0', 'compatible_brands': 'isommp42', 'creation_time': '2022-05-30T06:09:58.000000Z'}, 'inputs': [{'streams': [{'input_number': 0, 'stream_number': 0, 'stream_type': 'video', 'language': 'eng', 'default': True, 'size': [1280, 720], 'bitrate': 921, 'fps': 30.0, 'codec_name': 'h264', 'profile': '(Baseline)', 'metadata': {'Metadata': '', 'creation_time': '2022-05-30T06:09:58.000000Z', 'handler_name': 'Mainconcept MP4 Video Media Handler', 'vendor_id': '[0][0][0][0]', 'encoder': 'AVC Coding'}}, {'input_number': 0, 'stream_number': 1, 'stream_type': 'audio', 'language': 'eng', 'default': True, 'fps': 44100, 'bitrate': 125, 'metadata': {'Metadata': '', 'creation_time': '2022-05-30T06:09:58.000000Z', 'handler_name': 'Mainconcept MP4 Sound Media Handler', 'vendor_id': '[0][0][0][0]'}}], 'input_number': 0}], 'duration': 12.84, 'bitrate': 1049, 'start': 0.0, 'default_video_input_number': 0, 'default_video_stream_number': 0, 'video_codec_name': 'h264', 'video_profile': '(Baseline)', 'video_size': [1280, 720], 'video_bitrate': 921, 'video_fps': 30.0, 'default_audio_input_number': 0, 'default_audio_stream_number': 1, 'audio_fps': 44100, 'audio_bitrate': 125, 'video_duration': 12.84, 'video_n_frames': 385}
    /home/(path)/.local/lib/python3.13/site-packages/imageio_ffmpeg/binaries/ffmpeg-linux-x86_64-v7.0.2 -i myclip.mp4 -loglevel error -f image2pipe -vf scale=1280:720 -sws_flags bicubic -pix_fmt rgb24 -vcodec rawvideo -
    /home/(path)/.local/lib/python3.13/site-packages/moviepy/video/io/ffmpeg_reader.py:178: UserWarning: In file myclip.mp4, 2764800 bytes wanted but 0 bytes read at frame index 0 (out of a total 385 frames), at time 0.00/12.84 sec. Using the last valid frame instead.
    warnings.warn(
    Traceback (most recent call last):
    File "/home/customer/www/(customer)/public_html/tmp/(folder)/tmp/tmp2.py", line 11, in <module>
    clip = VideoFileClip(background_video_path)
    File "/home/(path)/.local/lib/python3.13/site-packages/decorator.py", line 235, in fun
    return caller(func, *(extras + args), **kw)
    File "/home/(path)/.local/lib/python3.13/site-packages/moviepy/decorators.py", line 94, in wrapper
    return func(*new_args, **new_kwargs)
    File "/home/(path)/.local/lib/python3.13/site-packages/moviepy/video/io/VideoFileClip.py", line 109, in __init__
    self.reader = FFMPEG_VideoReader(
    ~~~~~~~~~~~~~~~~~~^
    filename,
    ^^^^^^^^^
    ...<4 lines>...
    fps_source=fps_source,
    ^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
    File "/home/(path)/.local/lib/python3.13/site-packages/moviepy/video/io/ffmpeg_reader.py", line 81, in __init__
    self.initialize()
    ~~~~~~~~~~~~~~~^^
    File "/home/(path)/.local/lib/python3.13/site-packages/moviepy/video/io/ffmpeg_reader.py", line 155, in initialize
    self.last_read = self.read_frame()
    ~~~~~~~~~~~~~~~^^
    File "/home/(path)/.local/lib/python3.13/site-packages/moviepy/video/io/ffmpeg_reader.py", line 196, in read_frame
    raise IOError(
    ...<8 lines>...
    )
    OSError: MoviePy error: failed to read the first frame of video file myclip.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.



    Here's my code:

    import os
    import sys
    os.environ['OPENBLAS_NUM_THREADS'] = '8'
    import numpy as np
    from moviepy import *
    background_video_path = "myclip.mp4"
    clip = VideoFileClip(background_video_path)
    clip1 = clip.subclipped(2,3)
    clip1.write_videofile('conditiontest1.mp4',codec='libx264')


    This is running on Siteground on a server with the following versions installed: Fedora Linux 41 Python 3.13.3 Moviepy 2.1.2 Numpy 2.2.5 FFMPEG 7.1

    I installed a virtual machine here at home with the following versions: Fedora Linux 41 Python 3.13.0 Moviepy 2.1.2 Numpy 2.2.6 FFMPEG 7.0.2

    The script works on the virtual machine here at home, but fails with the above error on Siteground. I also have a VM running Debian with Python 3.9.2 where the script also works correctly. I'm not sure what the issue is here. I contacted Siteground support but they just said they don't support third party modules but just have them available for installation.

    I've tried a relative path (as in the script above) and explicitly putting the entire path in the VideoFileClip call to no avail. Each time the video is found (first thing in the results after running the script), but it can't read any of it. I've even redownloaded the video file from siteground just to check if something was corrupted in transit but it played perfectly even when downloading it from the server.

    I'm assuming something is configured differently on their server but I'm not sure where to begin troubleshooting it as I have it working locally. Any ideas?

    Continue reading...

Compartilhe esta Página