Blender V5.3
otio_round_trip_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "testing/testing.h"
7
8#include "MEM_guardedalloc.h"
9
10#include "BKE_anim_data.hh"
11#include "BKE_appdir.hh"
12#include "BKE_colortools.hh"
13#include "BKE_context.hh"
14#include "BKE_fcurve.hh"
15#include "BKE_idprop.hh"
16#include "BKE_lib_id.hh"
17#include "BKE_main.hh"
18#include "BKE_report.hh"
19#include "BKE_scene.hh"
20#include "BKE_sound.hh"
21
22#include "BLI_fileops.hh"
23#include "BLI_listbase.hh"
24#include "BLI_path_utils.hh"
25#include "BLI_string.hh"
26#include "BLI_vector.hh"
27
28#include "BLO_readfile.hh"
29
30#include "DNA_anim_types.h"
31#include "DNA_scene_types.h"
32#include "DNA_sequence_types.h"
33
34#include "RNA_access.hh"
35#include "RNA_prototypes.hh"
36
37#include "SEQ_add.hh"
38#include "SEQ_channels.hh"
39#include "SEQ_connect.hh"
40#include "SEQ_modifier.hh"
41#include "SEQ_sequencer.hh"
42#include "SEQ_sound.hh"
43#include "SEQ_time.hh"
44
45#include "IO_otio.hh"
46#include "otio_import.hh"
47#include "otio_metadata.hh"
48
49#include "opentimelineio/anyVector.h"
50#include "opentimelineio/clip.h"
51#include "opentimelineio/effect.h"
52#include "opentimelineio/externalReference.h"
53#include "opentimelineio/gap.h"
54#include "opentimelineio/generatorReference.h"
55#include "opentimelineio/imageSequenceReference.h"
56#include "opentimelineio/linearTimeWarp.h"
57#include "opentimelineio/marker.h"
58#include "opentimelineio/missingReference.h"
59#include "opentimelineio/serialization.h"
60#include "opentimelineio/stack.h"
61#include "opentimelineio/timeline.h"
62#include "opentimelineio/track.h"
63#include "opentimelineio/transition.h"
64
65namespace blender::io::otio {
66
68 protected:
69 Main *bmain = nullptr;
70 bContext *C = nullptr;
73 std::string directory;
74 std::string otio_path;
75
81
87
88 void SetUp() override
89 {
90 BlendfileLoadingBaseTest::SetUp();
92 C = CTX_create();
95 BKE_tempdir_init(nullptr);
96 directory = std::string(BKE_tempdir_session()) + SEP_STR + "io_otio";
97 ASSERT_TRUE(BLI_dir_create_recursive(directory.c_str()));
98 otio_path = directory + SEP_STR + "test.otio";
99 }
100
101 void TearDown() override
102 {
103 BLI_delete(directory.c_str(), true, true);
105 CTX_free(C);
108 }
109
110 Scene *new_scene(const char *name = "Timeline")
111 {
112 Scene *scene = BKE_scene_add(bmain, name);
113 scene->r.frs_sec = 24;
114 scene->r.frs_sec_base = 1.0f;
115 scene->r.sfra = 1;
116 scene->r.efra = 100;
117 seq::editing_ensure(scene);
118 return scene;
119 }
120
122 {
123 PointerRNA scene_ptr = RNA_id_pointer_create(&scene->id);
124 CTX_store_set(C, CTX_store_add(context_store, "sequencer_scene", &scene_ptr));
125 }
126
127 void export_otio(Scene *scene)
128 {
129 set_sequencer_scene(scene);
130 OTIOExportParams params;
131 STRNCPY(params.filepath, otio_path.c_str());
132 params.reports = &reports;
133 OTIO_export(C, params);
134 ASSERT_TRUE(BLI_exists(otio_path.c_str()));
135 }
136
138 {
140 OTIOImportParams params;
141 STRNCPY(params.filepath, otio_path.c_str());
142 params.reports = &reports;
143 return OTIO_import(C, params);
144 }
145
147 {
148 export_otio(scene);
149 Scene *imported = import_otio();
150 EXPECT_NE(imported, nullptr);
151 return imported;
152 }
153
154 SerializableObject::Retainer<Timeline> read_otio()
155 {
156 return dynamic_cast<Timeline *>(read_otio_file_with_workarounds(otio_path.c_str()));
157 }
158
159 void write_otio(Timeline *timeline)
160 {
161 ASSERT_TRUE(timeline->to_json_file(otio_path));
162 }
163
164 bool has_report(const char *text)
165 {
166 for (const Report &report : reports.list) {
167 if (strstr(report.message, text)) {
168 return true;
169 }
170 }
171 return false;
172 }
173
174 std::string asset_path(const char *relative_path)
175 {
176 char path[FILE_MAX];
177 BLI_path_join(path, sizeof(path), tests::flags_test_asset_dir().c_str(), relative_path);
178 return path;
179 }
180
181 std::string copy_image(const char *filename)
182 {
183 const std::string path = directory + SEP_STR + filename;
184 EXPECT_EQ(
185 BLI_copy(asset_path("io_tests/blend_scene/textures/alpha.png").c_str(), path.c_str()), 0);
186 return path;
187 }
188
189 static PointerRNA rna(Scene *scene, Strip *strip)
190 {
191 return RNA_pointer_create_discrete(&scene->id, RNA_Strip, strip);
192 }
193
195 ListBaseT<Strip> &seqbase,
196 const StripType type,
197 const char *name,
198 const int channel,
199 const int start,
200 const int length,
201 Strip *input1 = nullptr,
202 Strip *input2 = nullptr)
203 {
205 seq::add_load_data_init(&load_data, name, nullptr, start, channel);
206 load_data.effect.type = type;
207 load_data.effect.length = length;
208 load_data.effect.input1 = input1;
209 load_data.effect.input2 = input2;
210 return seq::add_effect_strip(scene, &seqbase, &load_data);
211 }
212
213 Strip *add_color(Scene *scene, const char *name, const int channel, const int start, int length)
214 {
215 return add_effect(scene, scene->ed->seqbase, STRIP_TYPE_COLOR, name, channel, start, length);
216 }
217
219 const char *name,
220 const int channel,
221 const int start,
222 const Span<const char *> filenames)
223 {
225 seq::add_load_data_init(&load_data, name, copy_image(filenames[0]).c_str(), start, channel);
226 load_data.image.count = filenames.size();
227 Strip *strip = seq::add_image_strip(bmain, scene, &scene->ed->seqbase, &load_data);
229 for (const int i : filenames.index_range()) {
230 copy_image(filenames[i]);
231 seq::add_image_load_file(scene, strip, i, filenames[i]);
232 }
233 return strip;
234 }
235
236 static std::string dump(Scene *scene, Strip *strip)
237 {
238 PointerRNA ptr = rna(scene, strip);
239 return serialize_json_to_string(rna_to_dictionary(ptr));
240 }
241
242 static void expect_same_strips(Scene *scene_a,
243 ListBaseT<Strip> &strips_a,
244 Scene *scene_b,
245 ListBaseT<Strip> &strips_b)
246 {
247 EXPECT_EQ(BLI_listbase_count(&strips_a), BLI_listbase_count(&strips_b));
248 for (Strip &a : strips_a) {
249 Strip *b = static_cast<Strip *>(BLI_findstring(&strips_b, a.name, offsetof(Strip, name)));
250 ASSERT_NE(b, nullptr) << a.name + 2;
251 EXPECT_EQ(a.type, b->type) << a.name + 2;
252 EXPECT_EQ(a.channel, b->channel) << a.name + 2;
253 EXPECT_EQ(a.left_handle(), b->left_handle()) << a.name + 2;
254 EXPECT_EQ(a.right_handle(scene_a), b->right_handle(scene_b)) << a.name + 2;
255 EXPECT_EQ(a.flag & SEQ_MUTE, b->flag & SEQ_MUTE) << a.name + 2;
256 EXPECT_EQ(dump(scene_a, &a), dump(scene_b, b)) << a.name + 2;
257 if (a.type == STRIP_TYPE_META) {
258 expect_same_strips(scene_a, a.seqbase, scene_b, b->seqbase);
259 }
260 }
261 }
262
264 {
265 Scene *imported = round_trip(scene);
266 ASSERT_NE(imported, nullptr);
267 expect_same_strips(scene, scene->ed->seqbase, imported, imported->ed->seqbase);
268 }
269};
270
271TEST_F(OTIOTest, TimelineSettings)
272{
273 Scene *scene = new_scene();
274 scene->r.frs_sec = 30;
275 scene->r.frs_sec_base = 1.001f;
276 TimeMarker *marker = MEM_new<TimeMarker>(__func__);
277 marker->frame = 10;
278 STRNCPY(marker->name, "Marker");
279 BLI_addtail(&scene->markers, marker);
280
281 Scene *imported = round_trip(scene);
282 ASSERT_NE(imported, nullptr);
283 EXPECT_EQ(imported->r.frs_sec, 30);
284 EXPECT_FLOAT_EQ(imported->r.frs_sec_base, 1.001f);
285 EXPECT_EQ(imported->r.sfra, 1);
286 ASSERT_EQ(BLI_listbase_count(&imported->markers), 1);
287 EXPECT_EQ(imported->markers.first()->frame, 10);
288 EXPECT_STREQ(imported->markers.first()->name, "Marker");
289 EXPECT_TRUE(read_otio()->tracks()->children().empty());
290}
291
292TEST_F(OTIOTest, GeneratorsAndModifiers)
293{
294 Scene *scene = new_scene();
295 Strip *color = add_color(scene, "Color", 1, 1, 10);
296 color->flag |= SEQ_MUTE;
297 PointerRNA color_ptr = rna(scene, color);
298 RNA_float_set(&color_ptr, "blend_alpha", 0.5f);
299 RNA_enum_set(&color_ptr, "blend_type", STRIP_BLEND_ADD);
300
301 Strip *text = add_effect(scene, scene->ed->seqbase, STRIP_TYPE_TEXT, "Text", 2, 5, 20);
302 PointerRNA text_ptr = rna(scene, text);
303 RNA_string_set(&text_ptr, "text", "Hello");
304 RNA_float_set(&text_ptr, "font_size", 42.0f);
305 RNA_float_set(&text_ptr, "outline_width", 0.25f);
306
308 CurveMapping &mapping = reinterpret_cast<CurvesModifierData *>(curves)->curve_mapping;
309 BKE_curvemap_insert(&mapping.cm[0], 0.5f, 0.75f);
310 BKE_curvemapping_changed(&mapping, false);
312 reinterpret_cast<BrightContrastModifierData *>(bright)->bright = 0.3f;
314
315 expect_round_trip(scene);
316}
317
318TEST_F(OTIOTest, MediaStrips)
319{
320#if !defined(WITH_FFMPEG) || !defined(WITH_AUDASPACE)
321 GTEST_SKIP() << "Movie or sound support is unavailable";
322#endif
323 Scene *scene = new_scene();
326 "Movie",
327 asset_path("sequence_editing/ffmpeg/media/grad_h264.mp4").c_str(),
328 5,
329 1);
330 Strip *movie = seq::add_movie_strip(bmain, scene, &scene->ed->seqbase, &load_data);
331 movie->handles_set(scene, movie->left_handle() + 2, movie->right_handle(scene) - 3);
332
333 seq::add_load_data_init(&load_data, "Sound", asset_path("sound/pink_panther.ogg").c_str(), 1, 2);
334 Strip *sound = seq::add_sound_strip(bmain, scene, &scene->ed->seqbase, &load_data);
335 sound->volume = 0.5f;
337 reinterpret_cast<SoundEqualizerModifierData *>(
339 100.0f,
340 1000.0f);
341 BKE_curvemap_insert(&graph->curve_mapping.cm[0], 500.0f, 3.0f);
342
343 add_images(scene, "Still", 3, 20, {"still.png"});
344 expect_round_trip(scene);
345}
346
347TEST_F(OTIOTest, ImageSequences)
348{
349 Scene *scene = new_scene();
350 add_images(scene, "Sequence", 1, 1, {"shot.0101.png", "shot.0103.png", "shot.0105.png"});
351 add_images(scene, "Unnamed", 2, 1, {"a.png", "b.png"});
352 Scene *imported = round_trip(scene);
353 ASSERT_NE(imported, nullptr);
354
355 SerializableObject::Retainer<Timeline> timeline = read_otio();
356 auto *reference = dynamic_cast<ImageSequenceReference *>(
357 timeline->find_clips()[0]->media_reference());
358 ASSERT_NE(reference, nullptr);
359 EXPECT_EQ(reference->name_prefix(), "shot.");
360 EXPECT_EQ(reference->start_frame(), 101);
361 EXPECT_EQ(reference->frame_step(), 2);
362 EXPECT_EQ(reference->frame_zero_padding(), 4);
363 EXPECT_TRUE(has_report("1 image sequence(s) with non-sequential filenames"));
364
365 Strip *sequence = seq::lookup_strip_by_name(imported->ed, "Sequence");
366 ASSERT_NE(sequence, nullptr);
367 EXPECT_EQ(sequence->data->stripdata_num, 3);
368 EXPECT_STREQ(sequence->data->stripdata[2].filename, "shot.0105.png");
369 EXPECT_EQ(seq::lookup_strip_by_name(imported->ed, "Unnamed"), nullptr);
370}
371
373{
374 Scene *scene = new_scene();
375 add_color(scene, "Before Start", 1, -5, 10);
376 add_color(scene, "A", 1, 10, 10);
377 add_color(scene, "B", 1, 40, 10);
378
380 seq::add_load_data_init(&load_data, "Meta", nullptr, 25, 1);
381 Strip *meta = seq::add_meta_strip(scene, &scene->ed->seqbase, &load_data);
382 add_effect(scene, meta->seqbase, STRIP_TYPE_COLOR, "Inner", 1, 25, 10);
384 meta->handles_set(scene, 27, 33);
385
386 add_color(scene, "High Channel", 7, 30, 5);
388 STRNCPY(channel->name, "Titles");
389 channel->flag |= SEQ_CHANNEL_MUTE;
390
391 Scene *imported = round_trip(scene);
392 ASSERT_NE(imported, nullptr);
393 expect_same_strips(scene, scene->ed->seqbase, imported, imported->ed->seqbase);
394 const SeqTimelineChannel *imported_channel = seq::channel_get_by_index(&imported->ed->channels,
395 7);
396 EXPECT_STREQ(imported_channel->name, "Titles");
397 EXPECT_TRUE(imported_channel->is_muted());
398}
399
400TEST_F(OTIOTest, MixedMeta)
401{
402#ifndef WITH_AUDASPACE
403 GTEST_SKIP() << "Sound support is unavailable";
404#endif
405 Scene *scene = new_scene();
407 seq::add_load_data_init(&load_data, "Meta", nullptr, 10, 1);
408 Strip *meta = seq::add_meta_strip(scene, &scene->ed->seqbase, &load_data);
409 add_effect(scene, meta->seqbase, STRIP_TYPE_COLOR, "Picture", 1, 10, 10);
411 &load_data, "Sound", asset_path("sound/pink_panther.ogg").c_str(), 10, 2);
412 Strip *sound = seq::add_sound_strip(bmain, scene, &meta->seqbase, &load_data);
413 sound->handles_set(scene, 10, 20);
415 meta->handles_set(scene, 10, 20);
416
417 Scene *imported = round_trip(scene);
418 ASSERT_NE(imported, nullptr);
419
420 SerializableObject::Retainer<Timeline> timeline = read_otio();
421 ASSERT_EQ(timeline->video_tracks().size(), 1);
422 ASSERT_EQ(timeline->audio_tracks().size(), 1);
423 EXPECT_NE(dynamic_cast<Stack *>(timeline->video_tracks()[0]->children().back().value), nullptr);
424 EXPECT_NE(dynamic_cast<Stack *>(timeline->audio_tracks()[0]->children().back().value), nullptr);
425
426 ASSERT_EQ(BLI_listbase_count(&imported->ed->seqbase), 2);
427 for (Strip &imported_meta : imported->ed->seqbase) {
428 EXPECT_EQ(imported_meta.type, STRIP_TYPE_META);
429 EXPECT_EQ(imported_meta.left_handle(), 10);
430 EXPECT_EQ(imported_meta.right_handle(imported), 20);
431 ASSERT_EQ(BLI_listbase_count(&imported_meta.seqbase), 1);
432 EXPECT_EQ(imported_meta.seqbase.first()->left_handle(), 10);
433 }
434}
435
436TEST_F(OTIOTest, SoundSubframeOffset)
437{
438#ifndef WITH_AUDASPACE
439 GTEST_SKIP() << "Sound support is unavailable";
440#endif
441 Scene *scene = new_scene();
442 const double fps = scene->frames_per_second();
443 const std::pair<const char *, float> cases[] = {{"Small", 0.3f}, {"Large", 0.7f}};
444 for (const int i : IndexRange(2)) {
447 &load_data, cases[i].first, asset_path("sound/pink_panther.ogg").c_str(), 1, i + 1);
448 Strip *sound = seq::add_sound_strip(bmain, scene, &scene->ed->seqbase, &load_data);
449 sound->handles_set(scene, 6, 26);
450 sound->sound_offset = cases[i].second / fps;
451 }
452
453 Scene *imported = round_trip(scene);
454 ASSERT_NE(imported, nullptr);
455
456 SerializableObject::Retainer<Timeline> timeline = read_otio();
457 for (const auto &[name, offset] : cases) {
458 const Strip *original = seq::lookup_strip_by_name(scene->ed, name);
459 const Strip *strip = seq::lookup_strip_by_name(imported->ed, name);
460 ASSERT_NE(strip, nullptr) << name;
461 EXPECT_EQ(strip->left_handle(), original->left_handle()) << name;
462 EXPECT_EQ(strip->right_handle(imported), original->right_handle(scene)) << name;
463 EXPECT_NEAR(strip->content_start() + strip->sound_offset * fps,
464 original->content_start() + original->sound_offset * fps,
465 1e-4)
466 << name;
467
468 for (const SerializableObject::Retainer<Clip> &clip : timeline->find_clips()) {
469 if (clip->name() == name) {
470 EXPECT_NEAR(clip->source_range()->start_time().value_rescaled_to(fps), 5.0 - offset, 1e-4)
471 << name;
472 }
473 }
474 }
475}
476
477TEST_F(OTIOTest, Transitions)
478{
479 Scene *scene = new_scene();
480 ListBaseT<Strip> &seqbase = scene->ed->seqbase;
481 Strip *a = add_color(scene, "A", 1, 1, 10);
482 Strip *b = add_color(scene, "B", 1, 16, 10);
483 add_effect(scene, seqbase, STRIP_TYPE_CROSS, "Cross", 1, 11, 5, a, b);
484
485 Strip *c = add_color(scene, "C", 2, 30, 10);
486 Strip *d = add_color(scene, "D", 2, 44, 10);
487 Strip *wipe = add_effect(scene, seqbase, STRIP_TYPE_WIPE, "Wipe", 2, 40, 4, c, d);
488 PointerRNA wipe_ptr = rna(scene, wipe);
489 RNA_float_set(&wipe_ptr, "angle", 0.5f);
490 RNA_enum_set(&wipe_ptr, "transition_type", SEQ_WIPE_CLOCK);
491 wipe->flag &= ~SEQ_USE_EFFECT_DEFAULT_FADE;
492 wipe->effect_fader = 0.25f;
493
494 expect_round_trip(scene);
495}
496
497TEST_F(OTIOTest, TransitionAcrossChannels)
498{
499 Scene *scene = new_scene();
500 Strip *a = add_color(scene, "A", 1, 1, 20);
501 Strip *b = add_color(scene, "B", 2, 10, 20);
502 add_effect(scene, scene->ed->seqbase, STRIP_TYPE_CROSS, "Cross", 3, 10, 11, a, b);
503
504 Scene *imported = round_trip(scene);
505 ASSERT_NE(imported, nullptr);
506 EXPECT_TRUE(has_report("Transition strip 'Cross' was not exported"));
507 EXPECT_EQ(seq::lookup_strip_by_name(imported->ed, "Cross"), nullptr);
508 EXPECT_EQ(BLI_listbase_count(&imported->ed->seqbase), 2);
509}
510
512{
513 Scene *scene = new_scene();
514 ListBaseT<Strip> &seqbase = scene->ed->seqbase;
515 Strip *a = add_color(scene, "A", 1, 1, 20);
516 Strip *b = add_color(scene, "B", 3, 1, 20);
517
518 Strip *speed = add_effect(scene, seqbase, STRIP_TYPE_SPEED, "Speed", 2, 1, 20, a);
519 PointerRNA speed_ptr = rna(scene, speed);
520 RNA_enum_set(&speed_ptr, "speed_control", SEQ_SPEED_MULTIPLY);
521 RNA_float_set(&speed_ptr, "speed_factor", 2.0f);
522
523 Strip *blur = add_effect(scene, seqbase, STRIP_TYPE_GAUSSIAN_BLUR, "Blur", 4, 1, 20, b);
524 PointerRNA blur_ptr = rna(scene, blur);
525 RNA_float_set(&blur_ptr, "size_x", 7.0f);
526
527 Strip *over = add_effect(scene, seqbase, STRIP_TYPE_ALPHAOVER, "Over", 5, 1, 20, a, b);
528 over->effect_fader = 0.5f;
529 over->flag &= ~SEQ_USE_EFFECT_DEFAULT_FADE;
530
531 expect_round_trip(scene);
532}
533
534TEST_F(OTIOTest, SceneStrip)
535{
536 Scene *scene = new_scene();
538 seq::add_load_data_init(&load_data, "Shot", nullptr, 1, 1);
539 load_data.scene = new_scene("Shot Scene");
540 seq::add_scene_strip(scene, &scene->ed->seqbase, &load_data);
541
542 Scene *imported = round_trip(scene);
543 ASSERT_NE(imported, nullptr);
544 EXPECT_TRUE(has_report("1 scene strip(s) found"));
545 EXPECT_NE(dynamic_cast<MissingReference *>(read_otio()->find_clips()[0]->media_reference()),
546 nullptr);
547 expect_same_strips(scene, scene->ed->seqbase, imported, imported->ed->seqbase);
548}
549
550TEST_F(OTIOTest, ForeignMetadata)
551{
552 auto timeline = SerializableObject::Retainer<Timeline>(
553 new Timeline("Foreign", RationalTime(0, 24)));
554 auto track = SerializableObject::Retainer<Track>(new Track());
555 AnyDictionary resolve;
556 resolve["Clip Color"] = std::string("Orange");
557 auto clip = SerializableObject::Retainer<Clip>(new Clip(
558 "Red",
559 new GeneratorReference("", "COLOR", TimeRange(RationalTime(0, 24), RationalTime(10, 24))),
560 TimeRange(RationalTime(0, 24), RationalTime(10, 24))));
561 clip->metadata()["Resolve_OTIO"] = resolve;
562 track->append_child(clip);
563 timeline->tracks()->append_child(track);
564 write_otio(timeline);
565
566 Scene *imported = import_otio();
567 ASSERT_NE(imported, nullptr);
568 Strip *strip = seq::lookup_strip_by_name(imported->ed, "Red");
569 ASSERT_NE(strip, nullptr);
571 IDProperty *group = IDP_GetPropertyFromGroup(strip->prop, "otio_metadata");
572 ASSERT_NE(group, nullptr);
573 EXPECT_NE(IDP_GetPropertyFromGroup(group, "Resolve_OTIO"), nullptr);
574
575 export_otio(imported);
576 AnyDictionary exported = read_otio()->find_clips()[0]->metadata();
577 EXPECT_EQ(std::any_cast<std::string>(
578 std::any_cast<AnyDictionary>(exported["Resolve_OTIO"])["Clip Color"]),
579 "Orange");
580}
581
582TEST_F(OTIOTest, ForeignTiming)
583{
584 auto timeline = SerializableObject::Retainer<Timeline>(
585 new Timeline("Foreign", RationalTime(90000, 25)));
586 auto track = SerializableObject::Retainer<Track>(new Track());
587 track->append_child(new Gap(RationalTime(10, 25)));
588 track->append_child(
589 new Clip("Still",
590 new ExternalReference("file:///a%20b/still.png",
591 TimeRange(RationalTime(1000, 25), RationalTime(100, 25))),
592 TimeRange(RationalTime(1010, 25), RationalTime(40, 50))));
593 timeline->tracks()->append_child(track);
594 write_otio(timeline);
595
596 Scene *imported = import_otio();
597 ASSERT_NE(imported, nullptr);
598 EXPECT_EQ(imported->r.frs_sec, 25);
599 EXPECT_EQ(imported->r.sfra, 90000);
600 Strip *strip = seq::lookup_strip_by_name(imported->ed, "Still");
601 ASSERT_NE(strip, nullptr);
603 EXPECT_EQ(strip->left_handle(), 90010);
604 EXPECT_EQ(strip->right_handle(imported), 90030);
605 EXPECT_EQ(BLI_path_cmp(strip->data->dirpath, "/a b/"), 0);
606}
607
608static AnyDictionary resolve_effect(const std::string &name,
609 const std::vector<std::pair<std::string, std::any>> &values)
610{
611 AnyVector parameters;
612 for (const auto &[id, value] : values) {
613 AnyDictionary parameter;
614 parameter["Parameter ID"] = id;
615 parameter["Parameter Value"] = value;
616 parameters.push_back(parameter);
617 }
618 AnyDictionary effect;
619 effect["Effect Name"] = name;
620 effect["Enabled"] = true;
621 effect["Parameters"] = parameters;
622 return effect;
623}
624
625TEST_F(OTIOTest, MarkerSchemaVersion2)
626{
627 auto timeline = SerializableObject::Retainer<Timeline>(
628 new Timeline("Markers", RationalTime(0, 24)));
629 timeline->tracks()->markers().push_back(
630 new Marker("Old", TimeRange(RationalTime(5, 24), RationalTime(1, 24)), std::nullopt));
631 std::string json = timeline->to_json_string();
632 const std::string schema = "\"Marker.3\"";
633 const size_t schema_start = json.find(schema);
634 ASSERT_NE(schema_start, std::string::npos);
635 json.replace(schema_start, schema.size(), "\"Marker.2\"");
636 fstream stream(otio_path, std::ios::out);
637 stream << json;
638 stream.close();
639
640 Scene *imported = import_otio();
641 ASSERT_NE(imported, nullptr);
642 ASSERT_EQ(BLI_listbase_count(&imported->markers), 1);
643 EXPECT_EQ(imported->markers.first()->frame, 5);
644 EXPECT_STREQ(imported->markers.first()->name, "Old");
645}
646
647TEST_F(OTIOTest, ResolveMetadata)
648{
649 const TimeRange range(RationalTime(0, 24), RationalTime(10, 24));
650 auto *generator = new GeneratorReference("Solid Color", "Solid Color", range);
651 generator->parameters()["Resolve_OTIO"] = AnyVector{
652 resolve_effect("Solid Color", {{"color", std::string("#ff8000")}})};
653 auto clip = SerializableObject::Retainer<Clip>(new Clip("Solid Color", generator, range));
654 AnyDictionary clip_resolve;
655 clip_resolve["Link Group ID"] = int64_t(1);
656 clip->metadata()["Resolve_OTIO"] = clip_resolve;
657
658 auto add_effect = [&](const AnyDictionary &resolve) {
659 auto *effect = new otio::Effect("", "Resolve Effect");
660 effect->metadata()["Resolve_OTIO"] = resolve;
661 clip->effects().push_back(effect);
662 };
663 add_effect(resolve_effect("Transform",
664 {{"transformationZoomX", 2.0},
665 {"transformationPan", 0.25},
666 {"transformationRotationAngle", 90.0}}));
667 add_effect(resolve_effect("Composite", {{"composite mode", int64_t(5)}, {"opacity", 50.0}}));
668
669 auto track = SerializableObject::Retainer<Track>(new Track("V1"));
670 AnyDictionary track_resolve;
671 track_resolve["Locked"] = true;
672 track->metadata()["Resolve_OTIO"] = track_resolve;
673 track->append_child(clip);
674 auto timeline = SerializableObject::Retainer<Timeline>(new Timeline("Resolve"));
675 timeline->tracks()->append_child(track);
676 write_otio(timeline);
677
678 Scene *imported = import_otio();
679 ASSERT_NE(imported, nullptr);
680 Strip *strip = seq::lookup_strip_by_name(imported->ed, "Solid Color");
681 ASSERT_NE(strip, nullptr);
682 ASSERT_EQ(strip->type, STRIP_TYPE_COLOR);
683 const SolidColorVars *color = static_cast<const SolidColorVars *>(strip->effectdata);
684 EXPECT_FLOAT_EQ(color->col[0], 1.0f);
685 EXPECT_NEAR(color->col[1], 128.0f / 255.0f, 1e-5f);
686 EXPECT_FLOAT_EQ(color->col[2], 0.0f);
687 EXPECT_FLOAT_EQ(strip->data->transform->scale_x, 2.0f);
688 EXPECT_FLOAT_EQ(strip->data->transform->scale_y, 1.0f);
689 EXPECT_FLOAT_EQ(strip->data->transform->xofs, 0.25f * imported->r.xsch);
690 EXPECT_NEAR(strip->data->transform->rotation, M_PI_2, 1e-5f);
691 EXPECT_EQ(strip->blend_mode, STRIP_BLEND_SCREEN);
692 EXPECT_FLOAT_EQ(strip->blend_opacity, 50.0f);
693 EXPECT_STREQ(seq::channel_get_by_index(&imported->ed->channels, 1)->name, "V1");
694 EXPECT_TRUE(seq::channel_get_by_index(&imported->ed->channels, 1)->is_locked());
695 EXPECT_NE(IDP_GetPropertyFromGroup(strip->prop, "otio_metadata"), nullptr);
696}
697
698TEST_F(OTIOTest, ReverseTimeWarp)
699{
700 const TimeRange range(RationalTime(0, 24), RationalTime(10, 24));
701 auto track = SerializableObject::Retainer<Track>(new Track());
702 for (const double time_scalar : {-1.0, -2.0}) {
703 auto *clip = new Clip(
704 std::to_string(time_scalar), new GeneratorReference("", "COLOR", range), range);
705 clip->effects().push_back(new LinearTimeWarp("", "", time_scalar));
706 track->append_child(clip);
707 }
708 auto timeline = SerializableObject::Retainer<Timeline>(new Timeline("Reverse"));
709 timeline->tracks()->append_child(track);
710 write_otio(timeline);
711
712 Scene *imported = import_otio();
713 ASSERT_NE(imported, nullptr);
714 ASSERT_EQ(BLI_listbase_count(&imported->ed->seqbase), 3);
715 int speed_strips = 0;
716 for (Strip &strip : imported->ed->seqbase) {
717 if (strip.type == STRIP_TYPE_SPEED) {
718 EXPECT_FLOAT_EQ(static_cast<SpeedControlVars *>(strip.effectdata)->speed_fader, 2.0f);
719 speed_strips++;
720 }
721 else {
722 EXPECT_TRUE(strip.flag & SEQ_REVERSE_FRAMES);
723 }
724 }
725 EXPECT_EQ(speed_strips, 1);
726}
727
728TEST_F(OTIOTest, ResolveEditMetadata)
729{
730 const TimeRange range(RationalTime(0, 24), RationalTime(20, 24));
731 auto image = SerializableObject::Retainer<Clip>(
732 new Clip("Image",
733 new ExternalReference(asset_path("sequence_editing/filter/31x17.png"), range),
734 range));
735 auto add_effect = [&](Clip &clip, const AnyDictionary &resolve) {
736 auto *effect = new otio::Effect("", "Resolve Effect");
737 effect->metadata()["Resolve_OTIO"] = resolve;
738 clip.effects().push_back(effect);
739 };
740 add_effect(*image, resolve_effect("Retime and Scaling", {{"scale", int64_t(3)}}));
741 add_effect(*image,
742 resolve_effect("Transform",
743 {{"transformationFlipX", true},
744 {"transformationAnchorPoint", AnyVector{0.1, 0.05}}}));
745 AnyDictionary composite = resolve_effect("Composite", {{"opacity", 100.0}});
746 AnyDictionary key_start;
747 key_start["Value"] = 100.0;
748 AnyDictionary key_end;
749 key_end["Value"] = 0.0;
750 AnyDictionary keys;
751 keys["0"] = key_start;
752 keys["10"] = key_end;
753 std::any_cast<AnyDictionary &>(
754 std::any_cast<AnyVector &>(composite["Parameters"])[0])["Key Frames"] = keys;
755 add_effect(*image, composite);
756
757 auto *wipe = new Transition(
758 "Edge Wipe", "Custom_Transition", RationalTime(5, 24), RationalTime(5, 24));
759 AnyDictionary wipe_resolve;
760 wipe_resolve["Effects"] = resolve_effect("Edge Wipe", {{"angle", int64_t(45)}});
761 wipe->metadata()["Resolve_OTIO"] = wipe_resolve;
762
763 AnyDictionary link_resolve;
764 link_resolve["Link Group ID"] = int64_t(7);
765 auto *linked_video = new Clip("Linked Video", new GeneratorReference("", "COLOR", range), range);
766 linked_video->metadata()["Resolve_OTIO"] = link_resolve;
767 auto *linked_other = new Clip("Linked Other", new GeneratorReference("", "COLOR", range), range);
768 linked_other->metadata()["Resolve_OTIO"] = link_resolve;
769
770 auto track_1 = SerializableObject::Retainer<Track>(new Track("V1"));
771 track_1->append_child(image);
772 track_1->append_child(wipe);
773 track_1->append_child(linked_video);
774 auto *adjustment = new Clip("Adjustment", new MissingReference(), range);
775 add_effect(*adjustment, resolve_effect("Effect", {}));
776 std::any_cast<AnyDictionary &>(
777 adjustment->effects()[0]->metadata()["Resolve_OTIO"])["Type"] = int64_t(74);
778 auto track_2 = SerializableObject::Retainer<Track>(new Track("V2"));
779 track_2->append_child(adjustment);
780 track_2->append_child(linked_other);
781
782 auto *sound = new Clip(
783 "Sound", new ExternalReference(asset_path("sound/pink_panther.ogg"), range), range);
784 add_effect(*sound,
785 resolve_effect("Fairlight Clip Volume and Fades",
786 {{"volume", 0.0}, {"faderIn", 4.0}, {"faderOut", 6.0}}));
787 auto track_3 = SerializableObject::Retainer<Track>(
788 new Track("A1", std::nullopt, Track::Kind::audio));
789 track_3->append_child(sound);
790
791 auto timeline = SerializableObject::Retainer<Timeline>(new Timeline("Resolve"));
792 timeline->tracks()->append_child(track_1);
793 timeline->tracks()->append_child(track_2);
794 timeline->tracks()->append_child(track_3);
795 write_otio(timeline);
796
797 Scene *imported = import_otio();
798 ASSERT_NE(imported, nullptr);
799 Strip *strip = seq::lookup_strip_by_name(imported->ed, "Image");
800 ASSERT_NE(strip, nullptr);
801 const float scale = std::max(imported->r.xsch / 31.0f, imported->r.ysch / 17.0f);
802 EXPECT_FLOAT_EQ(strip->data->transform->scale_x, scale);
803 EXPECT_FLOAT_EQ(strip->data->transform->origin[0],
804 0.5f + 0.1f * imported->r.ysch / (31.0f * scale));
805 EXPECT_FLOAT_EQ(strip->data->transform->origin[1],
806 0.5f + 0.05f * imported->r.ysch / (17.0f * scale));
807 EXPECT_TRUE(strip->flag & SEQ_FLIPX);
808
810 BKE_animdata_from_id(&imported->id),
811 "sequence_editor.strips_all[\"Image\"].blend_alpha",
812 0,
813 nullptr,
814 nullptr);
815 ASSERT_NE(fcurve, nullptr);
816 ASSERT_EQ(fcurve->totvert, 2);
817 EXPECT_FLOAT_EQ(fcurve->bezt[0].vec[1][0], strip->left_handle());
818 EXPECT_FLOAT_EQ(fcurve->bezt[0].vec[1][1], 1.0f);
819 EXPECT_FLOAT_EQ(fcurve->bezt[1].vec[1][0], strip->left_handle() + 10);
820 EXPECT_FLOAT_EQ(fcurve->bezt[1].vec[1][1], 0.0f);
821
822 Strip *wipe_strip = seq::lookup_strip_by_name(imported->ed, "Edge Wipe");
823 ASSERT_NE(wipe_strip, nullptr);
824 EXPECT_EQ(wipe_strip->type, STRIP_TYPE_WIPE);
825 EXPECT_NEAR(static_cast<WipeVars *>(wipe_strip->effectdata)->angle, M_PI_4, 1e-5f);
826
827 Strip *video = seq::lookup_strip_by_name(imported->ed, "Linked Video");
828 Strip *other = seq::lookup_strip_by_name(imported->ed, "Linked Other");
829 ASSERT_NE(video, nullptr);
830 ASSERT_NE(other, nullptr);
831 EXPECT_TRUE(seq::connected_strips_get(video).contains(other));
832
833 Strip *adjustment_strip = seq::lookup_strip_by_name(imported->ed, "Adjustment");
834 ASSERT_NE(adjustment_strip, nullptr);
835 EXPECT_EQ(adjustment_strip->type, STRIP_TYPE_ADJUSTMENT);
836
837 Strip *sound_strip = seq::lookup_strip_by_name(imported->ed, "Sound");
838 ASSERT_NE(sound_strip, nullptr);
840 BKE_animdata_from_id(&imported->id),
841 "sequence_editor.strips_all[\"Sound\"].volume",
842 0,
843 nullptr,
844 nullptr);
845 ASSERT_NE(volume, nullptr);
846 ASSERT_EQ(volume->totvert, 4);
847 const int start = sound_strip->left_handle();
848 const int end = sound_strip->right_handle(imported);
849 EXPECT_FLOAT_EQ(volume->bezt[0].vec[1][0], start);
850 EXPECT_FLOAT_EQ(volume->bezt[0].vec[1][1], 0.0f);
851 EXPECT_FLOAT_EQ(volume->bezt[1].vec[1][0], start + 4);
852 EXPECT_FLOAT_EQ(volume->bezt[1].vec[1][1], 1.0f);
853 EXPECT_FLOAT_EQ(volume->bezt[2].vec[1][0], end - 6);
854 EXPECT_FLOAT_EQ(volume->bezt[2].vec[1][1], 1.0f);
855 EXPECT_FLOAT_EQ(volume->bezt[3].vec[1][0], end);
856 EXPECT_FLOAT_EQ(volume->bezt[3].vec[1][1], 0.0f);
857}
858
859TEST_F(OTIOTest, KdenliveMetadata)
860{
861 const TimeRange range(RationalTime(0, 24), RationalTime(10, 24));
862 AnyDictionary kdenlive;
863 kdenlive["color"] = std::string("0xff8000ff");
864 AnyDictionary parameters;
865 parameters["kdenlive"] = kdenlive;
866 auto clip = SerializableObject::Retainer<Clip>(
867 new Clip("Orange",
868 new GeneratorReference("Orange", "kdenlive:SolidColor", range, parameters),
869 range));
870 auto track = SerializableObject::Retainer<Track>(new Track());
871 track->append_child(clip);
872 auto timeline = SerializableObject::Retainer<Timeline>(new Timeline("Kdenlive"));
873 timeline->tracks()->append_child(track);
874 write_otio(timeline);
875
876 Scene *imported = import_otio();
877 ASSERT_NE(imported, nullptr);
878 Strip *strip = seq::lookup_strip_by_name(imported->ed, "Orange");
879 ASSERT_NE(strip, nullptr);
880 ASSERT_EQ(strip->type, STRIP_TYPE_COLOR);
881 const SolidColorVars *color = static_cast<const SolidColorVars *>(strip->effectdata);
882 EXPECT_FLOAT_EQ(color->col[0], 1.0f);
883 EXPECT_NEAR(color->col[1], 128.0f / 255.0f, 1e-5f);
884 EXPECT_FLOAT_EQ(color->col[2], 0.0f);
885}
886
887TEST_F(OTIOTest, KdenliveTimeline)
888{
889 auto timeline = SerializableObject::Retainer<Timeline>(
890 new Timeline("Kdenlive", RationalTime(0, 24)));
891 auto track = SerializableObject::Retainer<Track>(new Track());
892 track->append_child(new Gap(RationalTime(10, 24)));
893 track->append_child(
894 new Clip("Missing",
895 new ExternalReference("file:///missing.mov",
896 TimeRange(RationalTime(0, 0), RationalTime(120, 0))),
897 TimeRange(RationalTime(5, 24), RationalTime(10, 24))));
898 timeline->tracks()->append_child(track);
899 write_otio(timeline);
900
901 Scene *imported = import_otio();
902 ASSERT_NE(imported, nullptr);
903 Strip *strip = seq::lookup_strip_by_name(imported->ed, "Missing");
904 ASSERT_NE(strip, nullptr);
905 EXPECT_FLOAT_EQ(strip->content_start(), 5.0f);
906 EXPECT_EQ(strip->left_handle(), 10);
907 EXPECT_EQ(strip->right_handle(imported), 20);
908}
909
910} // namespace blender::io::otio
File and directory operations.
#define M_PI_2
#define M_PI_4
#define FILE_MAX
#define BLI_path_join(...)
#define BLI_path_cmp
external readfile function prototypes.
Read Blender memory allocation and freeing.
constexpr IndexRange()=default
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
const T & data(const Action &owning_action) const
SerializableObject::Retainer< Timeline > read_otio()
Vector< std::unique_ptr< bContextStore > > context_store
static std::string dump(Scene *scene, Strip *strip)
std::string copy_image(const char *filename)
Strip * add_color(Scene *scene, const char *name, const int channel, const int start, int length)
Scene * new_scene(const char *name="Timeline")
static void expect_same_strips(Scene *scene_a, ListBaseT< Strip > &strips_a, Scene *scene_b, ListBaseT< Strip > &strips_b)
std::string asset_path(const char *relative_path)
Strip * add_images(Scene *scene, const char *name, const int channel, const int start, const Span< const char * > filenames)
bool has_report(const char *text)
void write_otio(Timeline *timeline)
Strip * add_effect(Scene *scene, ListBaseT< Strip > &seqbase, const StripType type, const char *name, const int channel, const int start, const int length, Strip *input1=nullptr, Strip *input2=nullptr)
static PointerRNA rna(Scene *scene, Strip *strip)
#define offsetof(t, d)
float4 load_data(StoredFloat4 data)
float length(VecOp< float, D >) RET
float3x3 scale(float3x3 mat, float2 scale)
#define EXPECT_NE(result, expect)
#define EXPECT_TRUE(result)
#define EXPECT_NEAR(result, expect, threshold)
std::string filename(const std::string_view &str, size_t pos)
static const std::any * parameter(const AnyDictionary &effect, const std::string &id)
static AnyDictionary resolve_effect(const std::string &name, const std::vector< std::pair< std::string, std::any > > &values)
SerializableObject * read_otio_file_with_workarounds(const char *filepath, opentimelineio::OPENTIMELINEIO_VERSION_NS::ErrorStatus *error_status)
AnyDictionary rna_to_dictionary(PointerRNA &ptr)
TEST_F(OTIOTest, TimelineSettings)
Strip * add_effect_strip(Scene *scene, ListBaseT< Strip > *seqbase, LoadData *load_data)
Definition strip_add.cc:174
Strip * lookup_strip_by_name(Editing *ed, const char *key)
Strip * add_image_strip(Main *bmain, Scene *scene, ListBaseT< Strip > *seqbase, LoadData *load_data)
Definition strip_add.cc:245
Strip * add_meta_strip(Scene *scene, ListBaseT< Strip > *seqbase, LoadData *load_data)
Definition strip_add.cc:376
void add_image_load_file(Scene *scene, Strip *strip, size_t strip_frame, const char *filename)
Definition strip_add.cc:210
void add_image_set_directory(Strip *strip, const char *dirpath)
Definition strip_add.cc:205
Editing * editing_ensure(Scene *scene)
Definition sequencer.cc:309
void time_update_meta_strip_range(const Scene *scene, Strip *strip_meta)
Strip * add_sound_strip(Main *, Scene *, ListBaseT< Strip > *, LoadData *)
Definition strip_add.cc:367
EQCurveMappingData * sound_equalizermodifier_add_graph(SoundEqualizerModifierData *semd, float min_freq, float max_freq)
Strip * add_scene_strip(Scene *scene, ListBaseT< Strip > *seqbase, LoadData *load_data)
Definition strip_add.cc:138
SeqTimelineChannel * channel_get_by_index(const ListBaseT< SeqTimelineChannel > *channels, const int channel_index)
Definition channels.cc:59
VectorSet< Strip * > connected_strips_get(const Strip *strip)
StripModifierData * modifier_new(Strip *strip, const char *name, eStripModifierType type)
Strip * add_movie_strip(Main *bmain, Scene *scene, ListBaseT< Strip > *seqbase, LoadData *load_data)
Definition strip_add.cc:394
void add_load_data_init(LoadData *load_data, const char *name, const char *path, const int start_frame, const int channel)
Definition strip_add.cc:69
__int64 int64_t
Definition BKE_text.h:90
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_reports_free(ReportList *reports)
Definition report.cc:106
PointerRNA RNA_id_pointer_create(ID *id)
bool BLI_dir_create_recursive(const char *dirname) ATTR_NONNULL()
Definition fileops_c.cc:416
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:91
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:818
Scene * OTIO_import(bContext *C, const OTIOImportParams &params)
Definition IO_otio.cc:20
Main * BKE_main_new()
Definition main.cc:93
bContextStore * CTX_store_add(Vector< std::unique_ptr< bContextStore > > &contexts, StringRef name, const PointerRNA *ptr)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
const char * BKE_tempdir_session() ATTR_WARN_UNUSED_RESULT ATTR_RETURNS_NONNULL
Definition appdir.cc:1283
bContext * CTX_create()
AnimData * BKE_animdata_from_id(const ID *id)
Definition anim_data.cc:93
int BLI_delete(const char *path, bool dir, bool recursive) ATTR_NONNULL()
FCurve * BKE_animadata_fcurve_find_by_rna_path(AnimData *animdata, const char *rna_path, const int rna_index, bAction **r_action, bool *r_driven)
void BKE_curvemapping_changed(CurveMapping *cumap, bool rem_doubles)
Scene * BKE_scene_add(Main *bmain, const char *name)
Definition scene.cc:2200
void CTX_free(bContext *C)
@ SEQ_USE_EFFECT_DEFAULT_FADE
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:531
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
void BKE_main_free(Main *bmain)
Definition main.cc:202
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
int BLI_copy(const char *path_src, const char *path_dst) ATTR_NONNULL()
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
CurveMapPoint * BKE_curvemap_insert(CurveMap *cuma, float x, float y)
void CTX_data_main_set(bContext *C, Main *bmain)
void OTIO_export(bContext *C, const OTIOExportParams &params)
Definition IO_otio.cc:15
void CTX_store_set(bContext *C, const bContextStore *store)
@ eSeqModifierType_SoundEqualizer
@ eSeqModifierType_BrightContrast
void BKE_tempdir_init(const char *userdir)
Definition appdir.cc:1245
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ListBaseT< SeqTimelineChannel > channels
ListBaseT< Strip > seqbase
unsigned int totvert
char filepath[FILE_MAX]
Definition IO_otio.hh:20
char filepath[FILE_MAX]
Definition IO_otio.hh:27
ListBaseT< Report > list
Definition BKE_report.hh:79
const char * message
Definition BKE_report.hh:73
struct Editing * ed
ListBaseT< TimeMarker > markers
struct RenderData r
float length() const
Definition sky_math.h:294
#define SEP_STR
Definition unit.cc:41