I'm using moviepy to cut a clip into multiple equally-sized segments, and it's reading from a txt file of start and end values to cut the clip properly. The following is my code:
required_video_file = VideoFileClip(filename)
with open("times.txt") as f:
times = f.readlines()
times = [x.strip() for x in times]
for time in times:
starttime = int(time.split("-")[0])
endtime = int(time.split("-")[1])
required_video_file = required_video_file.subclip(starttime, endtime)
filen = str(times.index(time)+1)+".mp4"
required_video_file.write_videofile(filen, audio_codec='aac')
The current filename value is a 20-ish minute clip which has the times.txt file cut up into 30-second portions.
0-30
30-60
60-90
90-120
120-150
And so on. However, I get a valueerror when it tries to write the third file:
ValueError: t_start (60.00) should be smaller than the clip's duration (30.00).
I'm not sure why this error is happening, because the clip it's trying to create a subclip of is 20 minutes long, not 30 seconds.
FULL ERROR:
<moviepy.video.io.VideoFileClip.VideoFileClip object at 0x105e589a0>
Traceback (most recent call last):
File "vidsplitter.py", line 76, in <module>
required_video_file = required_video_file.subclip(starttime, endtime)
File "<decorator-gen-35>", line 2, in subclip
File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 89, in wrapper
return f(*new_a, **new_kw)
File "<decorator-gen-34>", line 2, in subclip
File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 32, in apply_to_mask
newclip = f(clip, *a, **k)
File "<decorator-gen-33>", line 2, in subclip
File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/decorators.py", line 43, in apply_to_audio
newclip = f(clip, *a, **k)
File "/Users/hypnoticocelot/Library/Python/3.8/lib/python/site-packages/moviepy/Clip.py", line 391, in subclip
raise ValueError(
ValueError: t_start (60.00) should be smaller than the clip's duration (30.00).