Siteground服务器上MoviePy调用VideoFileClip报“无法读取首帧”错误求助
MoviePy VideoFileClip在Siteground服务器报错:
OSError: MoviePy error: failed to read the first frame 错误现象
仅在Siteground服务器运行代码时触发上述错误,本地Fedora 41、Debian虚拟机中代码可正常执行。
错误详情
{'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.
运行代码
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')
环境对比
- 本地Fedora虚拟机:Fedora Linux 41、Python 3.13.0、Moviepy 2.1.2、Numpy 2.2.6、FFMPEG 7.0.2(正常运行)
- 本地Debian虚拟机:Python 3.9.2(正常运行)
- Siteground服务器:Fedora Linux 41、Python 3.13.3、Moviepy 2.1.2、Numpy 2.2.5、FFMPEG 7.1(触发错误)
已尝试的排查步骤
- 使用相对路径和绝对路径调用VideoFileClip,均无效
- 重新从服务器下载视频文件,确认文件未损坏
- 联系Siteground客服,对方表示仅提供安装环境,不支持第三方模块问题排查
请求解决思路
推测是服务器配置差异导致问题,但不知从何入手,求可行的排查方向和解决办法。
内容的提问来源于stack exchange,提问作者TurnkeyTech33
相关产品推荐
相关产品推荐

