-2

I try to merge a hand full of videos. Therefore i use Moviepy. Unlikely, moviepy gives me an error over about 20 lines and i don't know what exactly i did wrong.

My code is:

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()

When i run this, i get this error shown below:

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
JanHarm22
  • 1
  • 2
  • "moviepy gives me an error over about 20 lines and i don't know what exactly i did wrong" It spent 20 lines trying to explain to you what went wrong. Did you try reading any of it? For example, see the part where it says "failed to read the duration of file firstvideo.mp4"? – Karl Knechtel Apr 14 '23 at 08:50
  • sure i read that. But I am not sure how to fix that. I thought it might be a permission problem that moviepy cannot access the video. So i tried to give the path permission via "os.chmod(path, 777)". That also won't work. Do you have other suggestions? – JanHarm22 Apr 14 '23 at 09:53
  • What happens if you try using `ffmpeg` yourself from the command line to get the information? – Karl Knechtel Apr 14 '23 at 12:19
  • Then it say: "Impossible to open 'firstvideo.mp4' – JanHarm22 Apr 17 '23 at 06:40
  • Do you have the mp4 file open or being used when running the script. If so close it before running the script. – Gaurav Hazra May 26 '23 at 16:58

1 Answers1

-1

The error was simply in the for-loop (for videoPath in sorted(glob("*.mp4")):). This have to be changed to for videoPath in sorted(glob("*/*.mp4",recursive=True)):. MoviePy got not the right path for its operations. After this change it works without any problems!

JanHarm22
  • 1
  • 2