Moviepy - Create multiple subclips using times from a CSV file

I am creating a Python script that uses the MoviePy module to shoot clips from a larger video and combine them together.

The time for clips is described in detail in the CSV file, for example:

0.10

11.19

15,20

34.42 etc.

What I did is read the CSV file in a row line by line, and then using the subclip method from Moviepy a clip is created that is stored in the list of clips, however I get the IndexError-list index out of range.

What could be the problem (the code works fine if I do not use the subclass method with the values ​​from the CSV file)?

This is my code:

video= VideoFileClip('file')

clipsArray = [] 

import csv
with open('csv file', 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        startTime = row[0]
        endTime = row[1]
        clip = fullVideo.subclip(startTime, endTime)
        clipsArray.append(clip)

Error message:

File "C: \ Anaconda3 \ envs \ py35 \ lib \ site-packages \ spyderlib \ widgets \ externalshell \ sitecustomize.py", line 685, in the execfile startup file (file name, namespace)

"C:\Anaconda3\envs\py35\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", 85, execfile   exec (compile (open ( , 'rb'). read(), , 'exec'), )

"C:/spyder2-py3/program.py", 32,   clip = fullVideo.subclip(, ) #

"", 2,

"C:\Anaconda3\envs\py35\lib\site-packages\moviepy\decorators.py", 86,    (arg, name) zip (a, names)]

"C:\Anaconda3\envs\py35\lib\site-packages\moviepy\decorators.py", 86,    (arg, name) zip (a, names)]

"C:\Anaconda3\envs\py35\lib\site-packages\moviepy\tools.py", 78, cvsecs   find = re.findall(expr, time) [0]

IndexError:

CSV:

0,12 16,21 22,29 34,59 89,130 140,160 162,171

+4
1

, , , csv , startTime endTime , '0' '12' .

MoviePy :

  • (int float),
  • 'hh:mm:ss.dd' (, , , ), . '05:12:10.50' 5 12 10,5 .

,

startTime = float(row[0])
endTime = float(row[1])
clip = fullVideo.subclip(startTime, endTime)
+1

Source: https://habr.com/ru/post/1626406/


All Articles