forked from freder/cinemetrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_2_save-shots.py
49 lines (36 loc) · 1.24 KB
/
02_2_save-shots.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
# -*- coding: utf-8 -*-
import sys
import os
import os.path
OUTPUT_DIR_NAME = "shot_snapshots"
def main():
os.chdir(sys.argv[1])
#frames = [os.path.splitext(file)[0] for file in os.listdir(os.getcwd() + "\\" + OUTPUT_DIR_NAME) if not os.path.isdir(file)]
import glob
frames = [os.path.splitext( os.path.basename(file) )[0] for file in glob.glob(OUTPUT_DIR_NAME + "\\*.png")] #os.getcwd() + "\\" +
frames = [int(frame) for frame in frames]
import xml.etree.ElementTree as et
tree = et.parse("project.xml")
movie = tree.getroot()
# frame count
movie.set("frames", str( frames[-1] - frames[0] ))
movie.set("start_frame", str( frames[0] ))
movie.set("end_frame", str( frames[-1] - 1 ))
tree.write("project.xml")
f = open(os.path.join(os.getcwd(), "shots.txt"), "w")
for i, frame in enumerate(frames):
if i == len(frames)-1:
break
f.write(str(frame) + "\t" + str(frames[i+1]-1) + "\t" + str(frames[i+1] - frame) + "\n")
if i > 0:
diff = frames[i] - frames[i-1]
if abs(diff) <= 5:
print "%d -> %d: %d" % (frames[i-1], frames[i], diff)
f.close()
print "don't forget to add FPS information!"
raw_input("- done -")
return
# #########################
if __name__ == "__main__":
main()
# #########################