-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpr2resolve_interpretfootagefix.py
75 lines (60 loc) · 3.17 KB
/
pr2resolve_interpretfootagefix.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
66
67
68
69
70
71
72
73
74
75
import os
import sys
import xml.etree.ElementTree as et
timebase = 0
def drop_frame_convert(framerate):
converter = {
24: 23.976,
30: 29.97,
60: 59.94,
}
return converter[framerate]
print("Input full path of Premiere XML:")
# handle Python 2 and 3 input differences
if sys.version_info[0] < 3:
xml_fullpath = raw_input()
else:
xml_fullpath = input()
# Get path of input XML and set up output XML
base_path, xml_file_name = os.path.split(xml_fullpath)
name, ext = os.path.splitext(xml_file_name)
xml_out_fullpath = base_path + os.sep + name + "_fixed" + ext
txt_out_fullpath = base_path + os.sep + name + "_pr2resolve.txt"
report = open(txt_out_fullpath,'w')
report.write("*************************************************************************\n")
report.write("******************** FILES TO INTERPRET IN RESOLVE ********************\n")
report.write("*************************************************************************\n")
tree = et.parse(xml_fullpath)
root = tree.getroot()
interpreted_files = [] # will add files that need to be interpreted in Resolve, to be printed to user
for clipitem in root.find("sequence").find("media").find("video").iter("clipitem"):
if clipitem[4][1].text != 'TRUE':
timebase = int(clipitem[4][0].text)
else:
timebase = drop_frame_convert(int(clipitem[4][0].text))
if clipitem.find("file") is not None and len(clipitem.find("file")) is not 0:
file_rate = 0
if clipitem.find("file").find("rate").find("ntsc").text != 'TRUE':
file_rate = int(clipitem.find("file").find("rate").find("timebase").text)
else:
file_rate = drop_frame_convert(int(clipitem.find("file").find("rate").find("timebase").text))
if file_rate != timebase:
interpreted_files.append([clipitem.find("file").find("name").text, timebase, file_rate])
clipitem.find("file").find("timecode").find("rate").find("timebase").text = str(timebase)
clipitem.find("file").find("rate").find("timebase").text = str(timebase)
clipitem.find("file").find("media").find("video").find("samplecharacteristics").find("rate").find("timebase").text = str(timebase)
start_frame = int(clipitem.find("file").find("timecode").find("frame").text)
clipitem.find("file").find("timecode").find("frame").text = str(int(start_frame / float(file_rate) * timebase))
tree.write(xml_out_fullpath)
print("\n*************************************************************************")
print("******************** FILES TO INTERPRET IN RESOLVE ********************")
print("*************************************************************************\n")
for i in range(len(interpreted_files)):
line = (interpreted_files[i][0] + " " + str(interpreted_files[i][2]) + " > " + str(interpreted_files[i][1]))
print (line)
report.write(line + "\n")
print("\n*************************************************************************\n")
print("The new XML has been created at: " + xml_out_fullpath)
report.close()
print("A report has been created at: " + txt_out_fullpath)
print("\n*************************************************************************")