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
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!