1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
22 from . import parse_edl
25 def id_animdata_action_ensure(id_data
):
26 id_data
.animation_data_create()
27 animation_data
= id_data
.animation_data
28 if animation_data
.action
is None:
29 animation_data
.action
= bpy
.data
.actions
.new(name
="Scene Action")
32 def scale_meta_speed(sequence_editor
, strip_list
, strip_movie
, scale
):
35 strip_speed
= sequence_editor
.sequences
.new_effect(
39 frame_start
=dummy_frame
,
40 channel
=strip_movie
.channel
+ 1)
41 strip_list
.append(strip_speed
)
43 # not working in 2.6x :|
44 strip_speed
.use_frame_blend
= True
45 # meta = sequence_editor.new([strip_movie, strip_speed], 199, strip_movie.channel)
47 # XXX-Meta Operator Mess
48 scene
= sequence_editor
.id_data
49 # we _know_ there are no others selected
50 for strip
in strip_list
:
52 strip_movie
.select
= True
53 strip_speed
.select
= True
54 bpy
.ops
.sequencer
.meta_make()
55 strip_meta
= scene
.sequence_editor
.sequences
[-1] # XXX, weak assumption
56 assert(strip_meta
.type == 'META')
57 strip_list
.append(strip_meta
)
58 strip_movie
.select
= strip_speed
.select
= strip_meta
.select
= False
59 # XXX-Meta Operator Mess (END)
62 strip_movie
.frame_still_end
= int(strip_movie
.frame_duration
* (scale
- 1.0))
64 strip_speed
.multiply_speed
= 1.0 / scale
65 strip_meta
.frame_offset_end
= strip_movie
.frame_duration
- int(strip_movie
.frame_duration
* scale
)
72 def apply_dissolve_fcurve(strip_movie
, blendin
):
73 scene
= strip_movie
.id_data
74 id_animdata_action_ensure(scene
)
75 action
= scene
.animation_data
.action
77 data_path
= strip_movie
.path_from_id("blend_alpha")
78 blend_alpha_fcurve
= action
.fcurves
.new(data_path
, index
=0)
79 blend_alpha_fcurve
.keyframe_points
.insert(strip_movie
.frame_final_start
, 0.0)
80 blend_alpha_fcurve
.keyframe_points
.insert(strip_movie
.frame_final_end
, 1.0)
82 blend_alpha_fcurve
.keyframe_points
[0].interpolation
= 'LINEAR'
83 blend_alpha_fcurve
.keyframe_points
[1].interpolation
= 'LINEAR'
85 if strip_movie
.type != 'SOUND':
86 strip_movie
.blend_type
= 'ALPHA_OVER'
89 def replace_ext(path
, ext
):
90 return path
[:path
.rfind(".") + 1] + ext
93 def load_edl(scene
, filename
, reel_files
, reel_offsets
, global_offset
):
95 reel_files - key:reel <--> reel:filename
102 # frame_offset = -769
104 fps
= scene
.render
.fps
107 elist
= parse_edl
.EditList()
108 if not elist
.parse(filename
, fps
):
109 return "Unable to parse %r" % filename
111 scene
.sequence_editor_create()
112 sequence_editor
= scene
.sequence_editor
114 for strip
in sequence_editor
.sequences_all
:
121 edits
= elist
.edits
[:]
122 # edits.sort(key = lambda edit: int(edit.recIn))
127 if edit
.reel
.lower() in parse_edl
.BLACK_ID
:
130 frame_offset
= reel_offsets
[edit
.reel
]
132 src_start
= int(edit
.srcIn
) + frame_offset
134 # src_end = int(edit.srcOut) + frame_offset
135 # src_length = src_end - src_start
137 rec_start
= int(edit
.recIn
) + 1
138 rec_end
= int(edit
.recOut
) + 1
139 rec_length
= rec_end
- rec_start
141 # apply global offset
142 rec_start
+= global_offset
143 rec_end
+= global_offset
145 # print(src_length, rec_length, src_start)
147 if edit
.m2
is not None:
148 scale
= fps
/ edit
.m2
.fps
152 unedited_start
= rec_start
- src_start
153 offset_start
= src_start
- int(src_start
* scale
) # works for scaling up AND down
155 if edit
.transition_type
== parse_edl
.TRANSITION_CUT
and (not elist
.overlap_test(edit
)):
160 if edit
.reel
.lower() in parse_edl
.BLACK_ID
:
161 strip
= sequence_editor
.sequences
.new_effect(
164 frame_start
=rec_start
,
165 frame_end
=rec_start
+ max(1, rec_length
),
167 strip_list
.append(strip
)
168 final_strips
.append(strip
)
169 strip
.color
= 0.0, 0.0, 0.0
172 path_full
= reel_files
[edit
.reel
]
173 path_dironly
, path_fileonly
= os
.path
.split(path_full
)
175 if edit
.edit_type
& (parse_edl
.EDIT_VIDEO | parse_edl
.EDIT_VIDEO_AUDIO
):
176 # and edit.transition_type == parse_edl.TRANSITION_CUT:
179 strip
= sequence_editor
.sequences
.new_movie(
183 frame_start
=unedited_start
+ offset_start
)
184 strip_list
.append(strip
)
186 # return "Invalid input for movie"
188 # Apply scaled rec in bounds
190 meta
= scale_meta_speed(sequence_editor
, strip_list
, strip
, scale
)
196 final_strip
.frame_offset_start
= rec_start
- final_strip
.frame_final_start
197 final_strip
.frame_offset_end
= rec_end
- final_strip
.frame_final_end
199 final_strip
.frame_offset_end
+= (final_strip
.frame_final_end
- rec_end
)
202 if edit
.transition_duration
:
204 print("Error no previous strip")
206 new_end
= rec_start
+ int(edit
.transition_duration
)
207 for other
in prev_edit
.custom_data
:
208 if other
.type != 'SOUND':
209 other
.frame_offset_end
+= (other
.frame_final_end
- new_end
)
213 if edit
.transition_type
== parse_edl
.TRANSITION_DISSOLVE
:
214 apply_dissolve_fcurve(final_strip
, edit
.transition_duration
)
216 if edit
.transition_type
== parse_edl
.TRANSITION_WIPE
:
217 other_track
= track
+ 2
218 for other
in prev_edit
.custom_data
:
219 if other
.type != 'SOUND':
220 strip_wipe
= sequence_editor
.sequences
.new_effect(
224 frame_start
=dummy_frame
,
226 strip_list
.append(strip_wipe
)
228 from math
import radians
229 if edit
.wipe_type
== parse_edl
.WIPE_0
:
230 strip_wipe
.angle
= radians(+90)
232 strip_wipe
.angle
= radians(-90)
236 # strip.frame_offset_end = strip.frame_duration - int(edit.srcOut)
237 # end_offset = (unedited_start + strip.frame_duration) - end
238 # print start, end, end_offset
239 # strip.frame_offset_end = end_offset
244 final_strips
.append(final_strip
)
246 if edit
.edit_type
& (parse_edl
.EDIT_AUDIO | parse_edl
.EDIT_AUDIO_STEREO | parse_edl
.EDIT_VIDEO_AUDIO
):
248 if scale
== 1.0: # TODO - scaled audio
251 strip
= sequence_editor
.sequences
.new_sound(
255 frame_start
=unedited_start
+ offset_start
)
256 strip_list
.append(strip
)
259 # See if there is a wave file there
260 path_full_wav
= replace_ext(path_full
, "wav")
263 strip
= sequence_editor
.sequences
.new_sound(
265 filepath
=path_full_wav
,
267 frame_start
=unedited_start
+ offset_start
)
268 strip_list
.append(strip
)
270 # return "Invalid input for audio"
276 final_strip
.frame_offset_start
= rec_start
- final_strip
.frame_final_start
277 final_strip
.frame_offset_end
= rec_end
- final_strip
.frame_final_end
279 final_strip
.frame_offset_end
+= (final_strip
.frame_final_end
- rec_end
)
282 if edit
.transition_type
== parse_edl
.TRANSITION_DISSOLVE
:
283 apply_dissolve_fcurve(final_strip
, edit
.transition_duration
)
285 final_strips
.append(final_strip
)
288 for strip
in final_strips
:
289 # strip.frame_duration = length
290 strip
.name
= edit
.as_name()
291 edit
.custom_data
[:] = final_strips
298 for strip
in strip_list
:
306 elist
= parse_edl
.EditList()
307 _filename
= "/fe/edl/cinesoft/rush/blender_edl.edl"
309 if not elist
.parse(_filename
, _fps
):
311 reels
= elist
.reels_as_dict()
313 print(list(reels
.keys()))
315 # import pdb; pdb.set_trace()
316 msg
= load_edl(bpy
.context
.scene
,
318 {'tapec': "/fe/edl/cinesoft/rush/rushes3.avi"},
319 {'tapec': 0}) # /tmp/test.edl