-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbamboo.py
35 lines (28 loc) · 904 Bytes
/
bamboo.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
# coding: utf-8
import os
import csv
import glob
import subprocess
import sys
def screenshot(ts, src, dst):
cmd = [
'ffmpeg', '-ss', ts, '-i', src, '-y', '-f', 'image2', '-vframes', '1',
dst
]
res = subprocess.run(cmd, stdout=subprocess.PIPE)
sys.stdout.buffer.write(res.stdout)
def main():
dialogues = glob.glob('dialogues/*')
dialogues.sort()
for dialogue in dialogues:
dst_dir = 'images/%s' % os.path.split(dialogue)[-1].replace('.csv', '')
src = 'videos/%s' % os.path.split(dialogue)[-1].replace('.csv', '.mkv')
if not os.path.exists(dst_dir):
os.makedirs(dst_dir)
with open(dialogue) as f:
csv_reader = csv.reader(f)
for ts, _ in csv_reader:
dst = os.path.join(dst_dir, '%s.jpg' % ts)
screenshot(ts, src, dst)
if __name__ == '__main__':
main()