How to use OpenTimelineIO - 10 common examples

To help you get started, we’ve selected a few OpenTimelineIO examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PixarAnimationStudios / OpenTimelineIO / tests / test_console.py View on Github external
]
            with self.assertRaises(SystemExit):
                self.run_test()

            sys.argv = [
                'otioconvert',
                '-i', SCREENING_EXAMPLE_PATH,
                '-o', temp_file,
                '-O', 'otio_json',
                "--begin", "0,24",
                "--end", "0",
            ]
            with self.assertRaises(SystemExit):
                self.run_test()

            result = otio.adapters.read_from_file(temp_file, "otio_json")
            self.assertEquals(len(result.tracks[0]), 0)
            self.assertEquals(result.name, "Example_Screening.01")

        finally:
            shutil.rmtree(temp_dir)
github PixarAnimationStudios / OpenTimelineIO / tests / test_composition.py View on Github external
)
        self.assertEqual(
            sq.range_of_child_at_index(2).duration,
            otio.opentime.RationalTime(value=50, rate=24)
        )

        # should trim 5 frames off the front, and 5 frames off the back
        sq_sourcerange = otio.opentime.TimeRange(
            start_time=otio.opentime.RationalTime(5, 24),
            duration=otio.opentime.RationalTime(140, 24),
        )
        sq.source_range = sq_sourcerange
        self.assertEqual(
            sq.trimmed_range_of_child_at_index(0),
            otio.opentime.TimeRange(
                otio.opentime.RationalTime(5, 24),
                otio.opentime.RationalTime(45, 24)
            )
        )
        self.assertEqual(
            sq.trimmed_range_of_child_at_index(1),
            sq.range_of_child_at_index(1)
        )
        self.assertEqual(
            sq.trimmed_range_of_child_at_index(2),
            otio.opentime.TimeRange(
                otio.opentime.RationalTime(100, 24),
                otio.opentime.RationalTime(45, 24),
            )
        )

        # get the trimmed range in the parent
github PixarAnimationStudios / OpenTimelineIO / tests / test_opentime.py View on Github external
def test_long_running_timecode_24(self):
        final_frame_number = 24 * 60 * 60 * 24 - 1
        final_time = otio.opentime.from_frames(final_frame_number, 24)
        self.assertEqual(
            otio.opentime.to_timecode(final_time),
            "23:59:59:23"
        )

        step_time = otio.opentime.RationalTime(value=1, rate=24)

        # fetching this test function from the c++ module directly
        cumulative_time = otio._opentime._testing.add_many(
            step_time,
            final_frame_number
        )
        self.assertEqual(cumulative_time, final_time)

        # Adding by a non-multiple of 24
        for fnum in range(1113, final_frame_number, 1113):
            rt = otio.opentime.from_frames(fnum, 24)
            tc = otio.opentime.to_timecode(rt)
            rt2 = otio.opentime.from_timecode(tc, 24)
            self.assertEqual(rt, rt2)
            self.assertEqual(tc, otio.opentime.to_timecode(rt2))
github PixarAnimationStudios / OpenTimelineIO / tests / test_composition.py View on Github external
list(
                sq.each_clip(
                    otio.opentime.TimeRange(
                        otio.opentime.RationalTime(150, 24)
                    )
                )
            ),
            []
        )

        self.assertEqual(
            sq.transformed_time(otio.opentime.RationalTime(0, 24), clip1),
            otio.opentime.RationalTime(100, 24)
        )
        self.assertEqual(
            sq.transformed_time(otio.opentime.RationalTime(0, 24), clip2),
            otio.opentime.RationalTime(51, 24)
        )
        self.assertEqual(
            sq.transformed_time(otio.opentime.RationalTime(0, 24), clip3),
            otio.opentime.RationalTime(2, 24)
        )

        self.assertEqual(
            sq.transformed_time(otio.opentime.RationalTime(50, 24), clip1),
            otio.opentime.RationalTime(150, 24)
        )
        self.assertEqual(
            sq.transformed_time(otio.opentime.RationalTime(50, 24), clip2),
            otio.opentime.RationalTime(101, 24)
        )
        self.assertEqual(
github PixarAnimationStudios / OpenTimelineIO / tests / test_composition.py View on Github external
def test_iterating_over_dupes(self):
        timeline = otio.schema.Timeline()
        track = otio.schema.Track()
        timeline.tracks.append(track)
        clip = otio.schema.Clip(
            name="Dupe",
            source_range=otio.opentime.TimeRange(
                start_time=otio.opentime.RationalTime(10, 30),
                duration=otio.opentime.RationalTime(15, 30)
            )
        )

        # make several identical copies
        for i in range(10):
            dupe = copy.deepcopy(clip)
            track.append(dupe)
        self.assertEqual(len(track), 10)
        self.assertEqual(
            otio.opentime.TimeRange(
                start_time=otio.opentime.RationalTime(0, 30),
                duration=otio.opentime.RationalTime(150, 30)
            ),
            track.trimmed_range()
        )
github PixarAnimationStudios / OpenTimelineIO / tests / test_cmx_3600_adapter.py View on Github external
def test_nucoda_edl_write_with_double_transition(self):
        track = otio.schema.Track()
        tl = otio.schema.Timeline("Double Transition", tracks=[track])

        cl = otio.schema.Clip(
            metadata={'cmx_3600': {'reel': 'Reel1'}},
            source_range=otio.opentime.TimeRange(
                start_time=otio.opentime.RationalTime(24.0, 24.0),
                duration=otio.opentime.RationalTime(24.0, 24.0)
            )
        )
        trans = otio.schema.Transition(
            in_offset=otio.opentime.RationalTime(6.0, 24.0),
            out_offset=otio.opentime.RationalTime(6.0, 24.0)
        )
        cl2 = otio.schema.Clip(
            metadata={'cmx_3600': {'reel': 'Reel2'}},
            source_range=otio.opentime.TimeRange(
                start_time=otio.opentime.RationalTime(24.0, 24.0),
                duration=otio.opentime.RationalTime(24.0, 24.0)
            )
        )
        trans2 = otio.schema.Transition(
            in_offset=otio.opentime.RationalTime(6.0, 24.0),
            out_offset=otio.opentime.RationalTime(6.0, 24.0)
        )
        cl3 = otio.schema.Clip(
            metadata={'cmx_3600': {'reel': 'Reel3'}},
            source_range=otio.opentime.TimeRange(
github PixarAnimationStudios / OpenTimelineIO / tests / test_opentime.py View on Github external
def test_base_conversion(self):

        # from a number
        t = otio.opentime.RationalTime(10, 24)
        with self.assertRaises(TypeError):
            t.rescaled_to("foo")
        self.assertEqual(t.rate, 24)
        t = t.rescaled_to(48)
        self.assertEqual(t.rate, 48)

        # from another RationalTime
        t = otio.opentime.RationalTime(10, 24)
        t2 = otio.opentime.RationalTime(20, 48)
        t = t.rescaled_to(t2)
        self.assertEqual(t.rate, t2.rate)
github PixarAnimationStudios / OpenTimelineIO / tests / test_fcp7_xml_adapter.py View on Github external
start_time=opentime.RationalTime(1101071, 24),
            duration=opentime.RationalTime(1055, 24)
        )
        self.assertTrue(clips[0].source_range == source_range)

        available_range = opentime.TimeRange(
            start_time=opentime.RationalTime(1101071, 24),
            duration=opentime.RationalTime(1055, 24)
        )
        self.assertTrue(clips[0].available_range() == available_range)

        clip_1_range = clips[1].available_range()
        self.assertEqual(
            clip_1_range,
            opentime.TimeRange(
                opentime.RationalTime(),
                opentime.RationalTime(1, 24),
            )
        )

        # Test serialization
        tmp_path = tempfile.mkstemp(suffix=".xml", text=True)[1]
        adapters.write_to_file(timeline, tmp_path)

        # Similar to the test_roundtrip_disk2mem2disk above
        # the track name element among others will not be present in a new xml.
        with open(HIERO_XML_PATH, "r") as original_file:
            with open(tmp_path, "r") as output_file:
                self.assertNotEqual(original_file.read(), output_file.read())
github PixarAnimationStudios / OpenTimelineIO / tests / test_cmx_3600_adapter.py View on Github external
def test_nucoda_edl_write_fade_in(self):
        track = otio.schema.Track()
        tl = otio.schema.Timeline(
            "Example Fade In",
            tracks=[track]
        )

        trans = otio.schema.Transition(
            in_offset=otio.opentime.RationalTime(0.0, 24.0),
            out_offset=otio.opentime.RationalTime(12.0, 24.0)
        )
        cl = otio.schema.Clip(
            'My Clip',
            metadata={'cmx_3600': {'reel': 'My_Clip'}},
            media_reference=otio.schema.ExternalReference(
                target_url="/var/tmp/clip.001.exr"
            ),
            source_range=otio.opentime.TimeRange(
                start_time=otio.opentime.RationalTime(50.0, 24.0),
                duration=otio.opentime.RationalTime(26.0, 24.0)
            )
        )
        tl.tracks[0].extend([trans, cl])

        result = otio.adapters.write_to_string(
github PixarAnimationStudios / OpenTimelineIO / tests / test_json_backend.py View on Github external
def test_timerange(self):
        tr = otio.opentime.TimeRange()
        self.check_against_baseline(tr, "empty_timerange")