-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalign.py
42 lines (40 loc) · 1.3 KB
/
align.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import glob
import moviepy.editor
import argparse
import multiprocessing
import shutil
def savePeriod(path):
name = os.path.basename(path).replace(".mp4", '')
folder = os.path.join(
os.path.dirname(path),
name
)
if(os.path.isdir(folder)): shutil.rmtree(folder, ignore_errors=True)
video = moviepy.editor.VideoFileClip(path)
length = int(video.duration)
threshold = 2
if(length<threshold): return
os.makedirs(folder)
# for index in range(1):
period = video#.subclip(index, index+1)
number = len([i for i in period.iter_frames()])
# if(number!=threshold*25): continue
# if(os.path.isfile(f'{folder}/{name}_{index}.mp4')): continue
period.write_videofile(
f'{folder}/{name}_{number}.mp4',
codec="libx264",
logger=None,
temp_audiofile=f'{folder}/{name}_{number}.wav'
)
# continue
return
if(__name__=='__main__'):
definition = argparse.ArgumentParser()
definition.add_argument("--folder", default='【數位主播晚報】', type=str)
argument = definition.parse_args()
element = glob.glob(os.path.join(argument.folder, '*/*.mp4'))
element = [e for e in element if('video' not in e)]
core = 6
pool = multiprocessing.Pool(core)
_ = pool.map(savePeriod, element)