Let's say I want to download a youtube video that contains chapters like this:
and I want to download this video with each chapter as an individual video. i.e, a video with 5 chapters should be downloaded as 5 separate videos. We can do the following:
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
required_video_file = "filename.mp4"
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])
ffmpeg_extract_subclip(required_video_file, starttime, endtime, targetname=str(times.index(time)+1)+".mp4")
where times.txt contains the timestamps of each chapter. This way is very tedious. How can I improve this?
