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
|
# File 'lib/final_cut_pro/sequence_processor.rb', line 20
def process(sequences)
files = { }
clips = [ ]
_sequences = { }
[*sequences].each do |sequence|
sequence_id = sequence[:id]
clip_items = sequence[:clip_items]
next unless clip_items
clip_item_counter = 0
clip_items_count = clip_items.count
clip_items.each do |clip_item|
clip_item_counter += 1
clip_rate = clip_item[:rate]
clip_time_base = clip_rate[:timebase].to_f
clip_rate_ntsc = clip_rate[:ntsc] == 'TRUE' ? true : false
clip_frame_rate = convert_time_base(clip_time_base, clip_rate_ntsc)
clip_duration_frames = clip_item[:duration].to_i
clip_duration_seconds = clip_duration_frames / clip_frame_rate
clip_start_frame = clip_item[:start].to_i
clip_end_frame = clip_item[:end].to_i
clip_in_frame = clip_item[:in].to_i
clip_out_frame = clip_item[:out].to_i
file = clip_item[:file] || { }
file_id = file[:id]
if file.keys.count == 1
file = files[file_id]
else
files[file_id] = file
end
next unless file
file_timecode = file[:timecode] || { }
file_timecode_frame = file_timecode[:frame].to_i
file_rate = file[:rate] || { }
file_time_base = file_rate[:timebase]
file_rate_ntsc = (file_rate[:ntsc] == 'TRUE') ? true : false
file_frame_rate = convert_time_base(file_time_base, file_rate_ntsc)
file_in_frame = clip_in_frame
file_out_frame = clip_out_frame
file_to_clip_rate_ratio = (file_time_base.to_f / clip_time_base.to_f)
file_in_timecode = frames_to_timecode(file_in_frame, clip_frame_rate, clip_rate_ntsc, ':')
file_out_timecode = frames_to_timecode(file_out_frame, clip_frame_rate, clip_rate_ntsc, ':')
file_in_seconds = (file_in_frame/clip_frame_rate)
file_out_seconds = (file_out_frame/clip_frame_rate)
file_path_url = file[:pathurl] || ''
file_path = URI.unescape(file_path_url).scan(/.*:\/\/\w*(\/.*)/).flatten.first
file_in_frame_with_offset = file_timecode_frame + (file_in_frame * file_to_clip_rate_ratio)
file_out_frame_with_offset = file_timecode_frame + (file_out_frame * file_to_clip_rate_ratio)
file_in_timecode_with_offset = frames_to_timecode(file_in_frame_with_offset, file_frame_rate, file_rate_ntsc, ';')
file_out_timecode_with_offset = frames_to_timecode(file_out_frame_with_offset, file_frame_rate, file_rate_ntsc, ';')
clips << {
:start_frame => clip_start_frame,
:end_frame => clip_end_frame,
:timebase => clip_time_base,
:ntsc => clip_rate[:ntsc],
:frame_rate => clip_frame_rate,
:sequence => { :id => sequence_id },
:duration_in_seconds => clip_duration_seconds,
:duration_in_frames => clip_duration_frames,
:file => {
:id => file_id,
:pathurl => file_path_url,
:path => file_path,
:timecode => file_timecode,
:timebase => file_time_base,
:ntsc => file_rate_ntsc,
:frame_rate => file_frame_rate,
:in_frame => file_in_frame,
:out_frame => file_out_frame,
:in_seconds => file_in_seconds,
:out_seconds => file_out_seconds,
:in_timecode => file_in_timecode,
:out_timecode => file_out_timecode,
:in_frame_with_offset => file_in_frame_with_offset,
:out_frame_with_offset => file_out_frame_with_offset,
:in_timecode_with_offset => file_in_timecode_with_offset,
:out_timecode_with_offset => file_out_timecode_with_offset,
},
}
_sequences[sequence_id] = clips
end
end
_sequences
end
|