forked from happyhorseskull/you-can-datamosh-on-linux
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstyle_transfer.py
53 lines (42 loc) · 1.8 KB
/
style_transfer.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
#!/usr/bin/env python3
import argparse
from vector_util import *
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('-v', type=str, default='', dest='vector_file',
help='file containing vector data to transfer', required=False)
parser.add_argument('-e', type=str, default='', dest='extract_from',
help='video to extract motion vector data from', required=False)
parser.add_argument('-t', default='', type=str, dest='transfer_to', help='video to transfer motion vector data to')
parser.add_argument(default='', type=str, dest='output',
help='output file either for the final video, or for the vector data')
return parser.parse_args().__dict__
if __name__ == '__main__':
# get args
args = parse_args()
vector_file = args['vector_file']
extract_from = args['extract_from']
transfer_to = args['transfer_to']
output = args['output']
# check that either extract_from or vector_file is given
if not ((extract_from == '') ^ (vector_file == '')):
print('Only one of -v or -e must be given')
exit(0)
vectors = []
if extract_from:
# step 1a: extract vectors
vectors = get_vectors(extract_from)
# if we only have to extract the vectors, write to file and exit
if transfer_to == '':
with open(output, 'w') as f:
json.dump(vectors, f)
exit(0)
elif vector_file:
# step 1b: read vectors from file
if not transfer_to:
print('Please specify file to transfer vectors to using -t')
exit(0)
with open(vector_file, 'r') as f:
vectors = json.load(f)
# step 2: transfer vector data to file
apply_vectors(vectors, transfer_to, output)