1

I made a small script to concatenate some clips. The names of the clips are stored in another text file that is read from.

I get the error first that

in ffmpeg_parse_infos
line = [l for l in lines if keyword in l][index]
IndexError: list index out of range

then during that exception above, another occurs below

Traceback (most recent call last):
  File "e:\Projects\TwitchMontage\VideoCompilation\src\create_video.py", line 32, in <module>
    clips = create_clips_from_list(list)
  File "e:\Projects\TwitchMontage\VideoCompilation\src\create_video.py", line 20, in create_clips_from_list
    clip = VideoFileClip(str(video_file_path))
  File "C:\Users\Alejandro\AppData\Local\Programs\Python\Python38\lib\site-packages\moviepy\video\io\VideoFileClip.py", line 88, in __init__
    self.reader = FFMPEG_VideoReader(filename, pix_fmt=pix_fmt,
  File "C:\Users\Alejandro\AppData\Local\Programs\Python\Python38\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 35, in __init__
    infos = ffmpeg_parse_infos(filename, print_infos, check_duration,
  File "C:\Users\Alejandro\AppData\Local\Programs\Python\Python38\lib\site-packages\moviepy\video\io\ffmpeg_reader.py", line 289, in ffmpeg_parse_infos
    raise IOError(("MoviePy error: failed to read the duration of file %s.\n"
OSError: MoviePy error: failed to read the duration of file E:\Projects\TwitchMontage\VideoCompilation\VideoFiles\raw_clips\clip0.mp4

I suspect something is wrong with FFMPEG but I have no idea what to change to fix this. Is there any manipulation I can make to FFMPEG or the videos themselves to make them work with moviepy?

Code is below:

import os
from moviepy.editor import VideoFileClip, concatenate_videoclips

PATH_TO_VALID_CLIPS = 'VideoCompilation/ClipData/valid_clips.txt'
PATH_TO_RAW_CLIPS = 'E:\Projects\TwitchMontage\VideoCompilation\VideoFiles\\raw_clips'
os.environ['IMAGEIO_FFMPEG_EXE'] = 'ffmpeg'

def read_valid_clips_list():
    #read valid clips
    file = open(PATH_TO_VALID_CLIPS, 'r')
    list = file.readlines()
    return list

def create_clips_from_list(list):
    clips = []
    for i, filename in enumerate(list):
        print(str(i) + '\n')
        video_file_path = os.path.abspath(os.path.join(PATH_TO_RAW_CLIPS, filename))
        print(video_file_path + '\n')
        clip = VideoFileClip(str(video_file_path))
        clips.append(clip)

    return clips

def create_draft(clips):
    draft = concatenate_videoclips(clips)
    draft.write_videofile("VideoCompilation/VideoFiles/videos/draft.mp4")
    return draft

list = read_valid_clips_list()
clips = create_clips_from_list(list)
draft = create_draft(clips)

EDIT:

I discovered something strange. When I manually create the combined video, there are no errors but the video created is corrupted and unplayable.

sample code image

Alejandro
  • 73
  • 7
  • Maybe try some of the answers in here: https://stackoverflow.com/questions/42121508/moviepy-unable-to-read-duration-of-file – wkl Aug 21 '22 at 20:37

1 Answers1

0

Reading the filename from the file appended the '\n' character to the end. This can be removed with .strip() function for strings. This was causing initial errors. Additionally, the file video looked strange due to having clips with different resolutions. This can be fixed with parameter method='compose'.

Alejandro
  • 73
  • 7