-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdump_markers.py
167 lines (137 loc) · 4.88 KB
/
dump_markers.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from __future__ import (
unicode_literals,
absolute_import,
print_function,
division,
)
import avb
import sys
if bytes is not str:
unicode = str
def pretty_value(value):
if isinstance(value, bytearray):
return "bytearray(%d)" % len(value)
# return ''.join(format(x, '02x') for x in value)
return value
def avb_dump(obj, space=""):
propertie_keys = []
property_data = None
if isinstance(obj, avb.core.AVBObject):
print(space, unicode(obj))
space += " "
property_data = obj.property_data
for pdef in obj.propertydefs:
key = pdef.name
if key not in obj.property_data:
continue
propertie_keys.append(key)
elif isinstance(obj, dict):
propertie_keys = obj.keys()
propertie_keys.sort()
property_data = obj
else:
print(space, obj)
return
for key in propertie_keys:
value = property_data[key]
if isinstance(value, (avb.core.AVBObject, dict)):
print("%s%s:" % (space, key))
avb_dump(value, space + " ")
elif isinstance(value, list):
print("%s%s:" % (space, key))
for item in value:
# print(space, item)
pass
avb_dump(item, space + " ")
else:
if value is not None:
print("%s%s:" % (space, key), pretty_value(value))
def frames_to_timecode(frames, fps=24):
s, f = divmod(frames, fps)
m, s = divmod(s, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
return '{1:02d}:{2:02d}:{3:02d}:{4:02d}'.format(d, h,m,s,f)
def print_marker(pos, marker, track):
if track.component.media_kind == 'picture':
track_name= "V%d" % track.index
elif track.component.media_kind == 'sound':
track_name= "A%d" % track.index
else:
track_name= "%d" % track.index
user = marker.attributes.get("_ATN_CRM_USER", '')
color = marker.attributes.get("_ATN_CRM_COLOR", '')
comment = marker.attributes.get("_ATN_CRM_COM", '')
line = ' {:<25} {} {:<5} {:<10} {}'
print(line.format(user, frames_to_timecode(pos), track_name, color.lower(), comment))
def get_component_markers(c):
if 'attributes' not in c.property_data:
return []
attributes = c.attributes or {}
markers = attributes.get('_TMP_CRM', [])
if isinstance(c, avb.components.Sequence):
for item in c.components:
more_markers = get_component_markers(item)
markers.extend(more_markers)
elif isinstance(c, avb.trackgroups.TrackGroup):
for track in c.tracks:
if 'component' not in track.property_data:
continue
more_markers = get_component_markers(track.component)
markers.extend(more_markers)
return markers
def find_track_markers(track, start=0):
components = []
if isinstance(track.component, avb.components.Sequence):
components = track.component.components
else:
components = [track.component]
pos = start
marker_list = []
for item in components:
if isinstance(item, avb.trackgroups.TransitionEffect):
pos -= item.length
markers = get_component_markers(item)
for marker in markers:
print_marker(pos + marker.comp_offset, marker, track)
marker_list.append([ pos + marker.comp_offset, marker ])
if not isinstance(item, avb.trackgroups.TransitionEffect):
pos += item.length
return marker_list
def iter_tracks(avb_mob):
track_types = ('picture', 'sound','edgecode', 'timecode', 'DescriptiveMetadata')
track_dict = {}
for track in avb_mob.tracks:
media_kind = track.component.media_kind
if media_kind not in track_dict:
track_dict[media_kind] = []
track_dict[media_kind].append(track)
for track_type in track_types:
tracks = track_dict.get(track_type, [])
for track in tracks:
yield track
def dump_markers(mob):
timcodes = {}
for i, track in enumerate(iter_tracks(mob)):
if track.media_kind == 'timecode':
if not isinstance(track.component, avb.components.Timecode):
# avb_dump(track)
continue
fps = track.component.fps
start = track.component.start
timcodes[fps] = start
# avb_dump(track)
# print(fps, start, frames_to_timecode(start, fps))
for i, track in enumerate(iter_tracks(mob)):
edit_rate = track.component.edit_rate
tc_rate = int(edit_rate + 0.5)
start = timcodes.get(tc_rate, 0)
markers = find_track_markers(track, start)
def main(path):
with avb.open(path) as f:
for mob in f.content.toplevel():
print(mob.name)
dump_markers(mob)
# break
if __name__ == "__main__":
main(sys.argv[1])