-
Notifications
You must be signed in to change notification settings - Fork 21
/
scenescoop.py
65 lines (56 loc) · 2.05 KB
/
scenescoop.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
# ----
# Scenescoop
# Cristobal Valenzuela
# https://github.com/cvalenzuela/scenescoop
# ----
import argparse
from os import getcwd, path
from glob import glob
from time import time
from get_frames import extract_frames
from run_model import im2text
from make_scene import make_scene
CWD = getcwd()
TEMP_DIR = path.join(CWD, 'temp')
OUTPUT_DIR = path.join(CWD, 'outputs')
TRANSCRIPT_DIR = path.join(CWD, 'transcripts')
FPS = 1
def main(options):
'''
Video to img2text
'''
if(options.video is not None):
# 1) Extract frames
extract_frames(options.video, TEMP_DIR, FPS)
# 2) Run model with images. Send batches of 100.
imgs = glob(TEMP_DIR + '/*.jpg')
amount = len(imgs)
batches = [[]]
for i in range(len(imgs)):
if (i is not 0 and i%100 == 0):
batches.append([imgs[i]])
else:
batches[-1].append(imgs[i])
imgs_batches = []
for batch in batches:
imgs_batches.append(','.join(batch))
# 3) Run model
model = im2text(TEMP_DIR, TRANSCRIPT_DIR, options.name, imgs_batches, amount)
if (options.api):
return model
if(options.input_data is not None):
# 4) Make a movie
make_scene(OUTPUT_DIR, options.input_data, options.input_seconds, options.transform_src, options.transform_data, False)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Storiescoop')
parser.add_argument('--video', type=str, help='Video Source to transform')
parser.add_argument('--name', type=str, help='Name of the video', default=str(time()))
parser.add_argument('--input_data', type=str, help='Input Video. Must be a json file.')
parser.add_argument('--input_seconds', type=str, help='Input Video Seconds to create transformation. Example: 1,30')
parser.add_argument('--transform_src', type=str, help='Transform Video Source.')
parser.add_argument('--transform_data', type=str, help='Transform Video Data. Must be a json file.')
parser.add_argument('--api', type=str, help='API Request', default=False)
args = parser.parse_args()
main(args)