You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MoviePy拼接视频列表失败,求助问题排查

MoviePy合并视频报错:Permission denied无法读取视频时长

尝试用MoviePy合并多个MP4视频时,运行代码出现权限拒绝错误,无法读取目标视频文件的时长。

用户代码

import os
from glob import glob
from moviepy.editor import VideoFileClip, concatenate_videoclips

PathList = []
if os.path.isfile("concat_output.mp4"):
    os.remove("concat_output.mp4")
for videoPath in sorted(glob("*.mp4")):
    PathList.append(VideoFileClip(videoPath))
final = concatenate_videoclips(PathList)
final.write_videofile('concat_output.mp4')
final.close()

报错信息

Traceback (most recent call last):
  File "C:\Users\jharm\.conda\envs\python\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 285, in ffmpeg_parse_infos
    line = [l for l in lines if keyword in l][index]
IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\jharm\Documents\merge_vid.py", line 10, in <module>
    PathList.append(VideoFileClip(videoPath))
  File "C:\Users\jharm\.conda\envs\python\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 91, in __init__
    fps_source=fps_source)
  File "C:\Users\jharm\.conda\envs\python\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 36, in __init__
    fps_source)
  File "C:\Users\jharm\.conda\envs\python\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 291, in ffmpeg_parse_infos
    filename, infos))
OSError: MoviePy error: failed to read the duration of file firstvideo.mp4.
Here are the file infos returned by ffmpeg:

ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 9.2.1 (GCC) 20200122
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
firstvideo.mp4: Permission denied

解决方案

  • 检查文件读取权限:确保运行脚本的用户对firstvideo.mp4拥有读取权限。Windows可右键文件→属性→安全面板,为当前用户添加读取权限;Linux/macOS执行chmod +r firstvideo.mp4赋予读取权限。
  • 关闭占用文件的程序:如果该视频文件正在被播放器、剪辑软件等其他程序占用,会导致权限拒绝,关闭所有关联程序后重新运行脚本。
  • 验证文件路径正确性:在循环中添加打印语句,确认脚本获取的视频路径是否正确:
    for videoPath in sorted(glob("*.mp4")):
        print(f"当前处理文件:{videoPath}")
        PathList.append(VideoFileClip(videoPath))
    
  • 以管理员身份运行脚本:Windows右键命令提示符或IDE选择“以管理员身份运行”;Linux/macOS使用sudo python merge_vid.py(注意先切换到对应的conda环境)。

内容的提问来源于stack exchange,提问作者Godan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 18:25:01