1
1
#
2
- # Copyright (C) 2019 Vincent Pinon <vpinon @kde.org>
2
+ # Copyright (C) 2019 Kdenlive developers <kdenlive @kde.org>
3
3
#
4
4
# Licensed under the Apache License, Version 2.0 (the "Apache License")
5
5
# with the following modification; you may not use this file except in
@@ -60,15 +60,15 @@ def read_from_string(input_str):
60
60
rate = float (profile .get ("frame_rate_num" )) \
61
61
/ float (profile .get ("frame_rate_den" , 1 ))
62
62
timeline = otio .schema .Timeline (
63
- name = mlt .get ("name" , "Kdenlive imported timeline" ))
63
+ name = mlt .get ("name" , "Kdenlive imported timeline" ))
64
64
65
65
maintractor = mlt .find ("tractor[@global_feed='1']" )
66
66
for maintrack in maintractor .findall ("track" ):
67
67
if maintrack .get ("producer" ) == 'black_track' :
68
68
continue
69
69
subtractor = byid [maintrack .get ("producer" )]
70
70
track = otio .schema .Track (
71
- name = mlt_property (subtractor , "kdenlive:track_name" ))
71
+ name = mlt_property (subtractor , "kdenlive:track_name" ))
72
72
if bool (mlt_property (subtractor , "kdenlive:audio_track" )):
73
73
track .kind = otio .schema .TrackKind .Audio
74
74
else :
@@ -78,31 +78,31 @@ def read_from_string(input_str):
78
78
for item in playlist .iter ():
79
79
if item .tag == 'blank' :
80
80
gap = otio .schema .Gap (
81
- duration = time (item .get ("length" ), rate ))
81
+ duration = time (item .get ("length" ), rate ))
82
82
track .append (gap )
83
83
elif item .tag == 'entry' :
84
84
producer = byid [item .get ("producer" )]
85
85
service = mlt_property (producer , "mlt_service" )
86
86
available_range = otio .opentime .TimeRange (
87
87
start_time = time (producer .get ("in" ), rate ),
88
- duration = time (producer .get ("out" ), rate )
89
- - time (producer .get ("in" ), rate ))
88
+ duration = time (producer .get ("out" ), rate ) -
89
+ time (producer .get ("in" ), rate ))
90
90
source_range = otio .opentime .TimeRange (
91
91
start_time = time (item .get ("in" ), rate ),
92
- duration = time (item .get ("out" ), rate )
93
- - time (item .get ("in" ), rate ))
92
+ duration = time (item .get ("out" ), rate ) -
93
+ time (item .get ("in" ), rate ))
94
94
# media reference clip
95
95
reference = None
96
96
if service in ["avformat" , "avformat-novalidate" , "qimage" ]:
97
97
reference = otio .schema .ExternalReference (
98
- target_url = mlt_property (producer , 'kdenlive:originalurl' )
99
- or mlt_property (producer , 'resource' ),
100
- available_range = available_range )
98
+ target_url = mlt_property (producer , 'kdenlive:originalurl' ) or
99
+ mlt_property (producer , 'resource' ),
100
+ available_range = available_range )
101
101
elif service == "color" :
102
102
reference = otio .schema .GeneratorReference (
103
- generator_kind = "SolidColor" ,
104
- parameters = {"color" : mlt_property (producer , "resource" )},
105
- available_range = available_range )
103
+ generator_kind = "SolidColor" ,
104
+ parameters = {"color" : mlt_property (producer , "resource" )},
105
+ available_range = available_range )
106
106
clip = otio .schema .Clip (
107
107
name = mlt_property (producer , 'kdenlive:clipname' ),
108
108
source_range = source_range ,
@@ -140,11 +140,11 @@ def read_from_string(input_str):
140
140
for transition in maintractor .findall ("transition" ):
141
141
kdenlive_id = mlt_property (transition , "kdenlive_id" )
142
142
if kdenlive_id == "wipe" :
143
- timeline .tracks [int (mlt_property (transition , "b_track" ))- 1 ].append (
144
- otio .schema .Transition (
145
- transition_type = otio .schema .TransitionTypes .SMPTE_Dissolve ,
146
- in_offset = time (transition .get ("in" ), rate ),
147
- out_offset = time (transition .get ("out" ), rate )))
143
+ timeline .tracks [int (mlt_property (transition , "b_track" )) - 1 ].append (
144
+ otio .schema .Transition (
145
+ transition_type = otio .schema .TransitionTypes .SMPTE_Dissolve ,
146
+ in_offset = time (transition .get ("in" ), rate ),
147
+ out_offset = time (transition .get ("out" ), rate )))
148
148
149
149
return timeline
150
150
@@ -165,22 +165,22 @@ def write_to_string(input_otio):
165
165
"producer" : "main_bin" })
166
166
rate = input_otio .duration ().rate
167
167
(rate_num , rate_den ) = {
168
- 23.98 : (24000 , 1001 ),
169
- 29.97 : (30000 , 1001 ),
170
- 59.94 : (60000 , 1001 )
171
- }.get (round (float (rate ), 2 ), (int (rate ), 1 ))
168
+ 23.98 : (24000 , 1001 ),
169
+ 29.97 : (30000 , 1001 ),
170
+ 59.94 : (60000 , 1001 )
171
+ }.get (round (float (rate ), 2 ), (int (rate ), 1 ))
172
172
ET .SubElement (mlt , "profile" , {
173
- "description" : f"HD 1080p { rate } fps" ,
174
- "frame_rate_num" : str (rate_num ),
175
- "frame_rate_den" : str (rate_den ),
176
- "width" : "1920" ,
177
- "height" : "1080" ,
178
- "display_aspect_num" : "16" ,
179
- "display_aspect_den" : "9" ,
180
- "sample_aspect_num" : "1" ,
181
- "sample_aspect_den" : "1" ,
182
- "colorspace" : "709" ,
183
- "progressive" : "1" })
173
+ "description" : f"HD 1080p { rate } fps" ,
174
+ "frame_rate_num" : str (rate_num ),
175
+ "frame_rate_den" : str (rate_den ),
176
+ "width" : "1920" ,
177
+ "height" : "1080" ,
178
+ "display_aspect_num" : "16" ,
179
+ "display_aspect_den" : "9" ,
180
+ "sample_aspect_num" : "1" ,
181
+ "sample_aspect_den" : "1" ,
182
+ "colorspace" : "709" ,
183
+ "progressive" : "1" })
184
184
185
185
# build media library, indexed by url
186
186
main_bin = ET .Element ("playlist" , {"id" : "main_bin" })
@@ -203,9 +203,9 @@ def write_to_string(input_otio):
203
203
continue
204
204
producer = ET .SubElement (mlt , "producer" , {
205
205
"id" : f"producer{ len (media_prod )} " ,
206
- "in" : str (int (clip .media_reference .available_range .start_time .value )),
207
- "out" : str (int ((clip .media_reference .available_range .start_time
208
- + clip .media_reference .available_range .duration ).value ))})
206
+ "in" : str (int (clip .media_reference .available_range .start_time .value )),
207
+ "out" : str (int ((clip .media_reference .available_range .start_time +
208
+ clip .media_reference .available_range .duration ).value ))})
209
209
ET .SubElement (main_bin , "entry" , {"producer" : f"producer{ len (media_prod )} " })
210
210
add_property (producer , "mlt_service" , service )
211
211
add_property (producer , "resource" , resource )
@@ -214,7 +214,7 @@ def write_to_string(input_otio):
214
214
media_prod [resource ] = producer
215
215
216
216
unsupported = ET .SubElement (mlt , "producer" ,
217
- {"id" : "unsupported" , "in" : "0" , "out" : "10000" })
217
+ {"id" : "unsupported" , "in" : "0" , "out" : "10000" })
218
218
add_property (unsupported , "mlt_service" , "qtext" )
219
219
add_property (unsupported , "family" , "Courier" )
220
220
add_property (unsupported , "fgcolour" , "#ff808080" )
@@ -240,21 +240,21 @@ def write_to_string(input_otio):
240
240
add_property (subtractor , "kdenlive:track_name" , track .name )
241
241
242
242
ET .SubElement (subtractor , "track" , {
243
- "producer" : f"playlist{ track_count } _1" ,
244
- "hide" : "audio" if track .kind == otio .schema .TrackKind .Video
245
- else "video" })
243
+ "producer" : f"playlist{ track_count } _1" ,
244
+ "hide" : "audio" if track .kind == otio .schema .TrackKind .Video
245
+ else "video" })
246
246
ET .SubElement (subtractor , "track" , {
247
- "producer" : f"playlist{ track_count } _2" ,
248
- "hide" : "audio" if track .kind == otio .schema .TrackKind .Video
249
- else "video" })
247
+ "producer" : f"playlist{ track_count } _2" ,
248
+ "hide" : "audio" if track .kind == otio .schema .TrackKind .Video
249
+ else "video" })
250
250
playlist = ET .SubElement (mlt , "playlist" ,
251
251
{"id" : f"playlist{ track_count } _1" })
252
252
playlist_ = ET .SubElement (mlt , "playlist" ,
253
253
{"id" : f"playlist{ track_count } _2" })
254
254
if track .kind == otio .schema .TrackKind .Audio :
255
255
add_property (subtractor , "kdenlive:audio_track" , "1" )
256
- add_property (playlist , "kdenlive:audio_track" , "1" )
257
- add_property (playlist_ , "kdenlive:audio_track" , "1" )
256
+ add_property (playlist , "kdenlive:audio_track" , "1" )
257
+ add_property (playlist_ , "kdenlive:audio_track" , "1" )
258
258
259
259
for item in track :
260
260
if isinstance (item , otio .schema .Gap ):
@@ -272,13 +272,13 @@ def write_to_string(input_otio):
272
272
and item .media_reference .generator_kind == "SolidColor" :
273
273
resource = item .media_reference .parameters ["color" ]
274
274
ET .SubElement (playlist , "entry" , {
275
- "producer" : media_prod [resource ].attrib ["id" ]
276
- if item .media_reference
277
- and not item .media_reference .is_missing_reference
278
- else "unsupported" ,
279
- "in" : str (int (item .source_range .start_time .value )),
280
- "out" : str (int ((item .source_range .duration
281
- + item .source_range .start_time ).value ))})
275
+ "producer" : media_prod [resource ].attrib ["id" ]
276
+ if item .media_reference and
277
+ not item .media_reference .is_missing_reference
278
+ else "unsupported" ,
279
+ "in" : str (int (item .source_range .start_time .value )),
280
+ "out" : str (int ((item .source_range .duration +
281
+ item .source_range .start_time ).value ))})
282
282
# Effects handling to be added
283
283
# for effect in item.effects:
284
284
elif isinstance (item , otio .schema .Transition ):
@@ -292,7 +292,8 @@ def write_to_string(input_otio):
292
292
293
293
if __name__ == "__main__" :
294
294
# timeline = otio.adapters.read_from_file("tests/sample_data/kdenlive_example.kdenlive")
295
- timeline = read_from_string (open ("tests/sample_data/kdenlive_example.kdenlive" , "r" ).read ())
295
+ timeline = read_from_string (
296
+ open ("tests/sample_data/kdenlive_example.kdenlive" , "r" ).read ())
296
297
# print(otio.adapters.write_to_string(timeline, "otio_json"))
297
298
print (str (timeline ).replace ("otio.schema" , "\n otio.schema" ))
298
299
xml = write_to_string (timeline )
0 commit comments