Zulko / moviepy

Video editing with Python
https://zulko.github.io/moviepy/
MIT License
12.08k stars 1.51k forks source link

VideoFileClip.write_videofile stops with an error message #2107

Open hrrad opened 5 months ago

hrrad commented 5 months ago

i am using Python 3.11.4 on windows 10 and it is a tkinter app. the version of moviepy is: 1.0.3

the error message is: File "G:\Programme\Python\Lib\site-packages\moviepy\video\compositing\concatenate.py", line 85, in make_frame return clips[i].get_frame(t - tt[i])


IndexError: list index out of range
when the error occurs the value of i is going from 0 to 2, but it should go from 0 to 1, as i am only concatenating 2 subclips.
the error message comes a few frames before the writing would be complete.

The error message does not occur for all video files, but only for some.
The error message only appears, when the problematic video file is processed after another videofile, that does not have the problem.
When the problematic video file is processed as the first video file after the start of the program, then the error does not appear.
So i think that something is not set back correctly after processing the first video file.
My source code for processing one video file looks like that:
video_clip = VideoFileClip(video_file)
cut_clip1 = video_clip.subclip(start1, end1)
cut_clip2 = video_clip.subclip(start2, end2)
final_clip = concatenate_videoclips([cut_clip1, cut_clip2])
final_clip.write_videofile(video_directory+"/"+video_filename+".mp4", codec="libx264", audio_codec="aac")
final_clip.close()
video_clip.close()

i found a workaround by using try.. except:
            try:
                return clips[i].get_frame(t - tt[i])
            except:
                print("Exception")
                return clips[i-1].get_frame(t - tt[i])

but this is not the real solution as it puts a few frames from the beginning of the cut_clip2 to the end of the video.
keikoro commented 4 months ago

Please always code format any code snippets you include in your issues to make it easier for others to parse them.

You can either type the formatting out yourself – 3 backticks on the line before the code block, 3 on the line after – or use the button that GitHub provides via its interface.