How to use the opentimelineio.opentime function in OpenTimelineIO

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_opentime.py View on Github external
def test_to_timecode_mixed_rates(self):
        timecode = "00:06:56:17"
        t = otio.opentime.from_timecode(timecode, 24)
        self.assertEqual(timecode, otio.opentime.to_timecode(t))
        self.assertEqual(timecode, otio.opentime.to_timecode(t, 24))
        self.assertNotEqual(timecode, otio.opentime.to_timecode(t, 12))
github PixarAnimationStudios / OpenTimelineIO / tests / test_generator_reference.py View on Github external
def test_constructor(self):
        self.assertEqual(self.gen.generator_kind, "SMPTEBars")
        self.assertEqual(self.gen.name, "SMPTEBars")
        self.assertEqual(self.gen.parameters, {"test_param": 5.0})
        self.assertEqual(self.gen.metadata, {"foo": "bar"})
        self.assertEqual(
            self.gen.available_range,
            otio.opentime.TimeRange(
                otio.opentime.RationalTime(0, 24),
                otio.opentime.RationalTime(100, 24),
            )
github PixarAnimationStudios / OpenTimelineIO / tests / test_item.py View on Github external
def test_not_both_source_range_and_duration(self):
        with self.assertRaises(TypeError):
            otio.schema.Gap(
                duration=otio.opentime.RationalTime(10, 24),
                source_range=otio.opentime.TimeRange(
                    otio.opentime.RationalTime(0, 24),
                    otio.opentime.RationalTime(10, 24)
                )
            )

        self.assertJsonEqual(
            otio.schema.Gap(
                duration=otio.opentime.RationalTime(10, 24),
            ),
            otio.schema.Gap(
                source_range=otio.opentime.TimeRange(
                    otio.opentime.RationalTime(0, 24),
                    otio.opentime.RationalTime(10, 24)
                )
github PixarAnimationStudios / OpenTimelineIO / tests / test_track_algo.py View on Github external
def test_expand_surrounded_by_clips(self):
        name = "test"
        rt = otio.opentime.RationalTime(5, 24)
        rt_2 = otio.opentime.RationalTime(1, 24)
        tr = otio.opentime.TimeRange(rt, rt + rt)
        avail_tr = otio.opentime.TimeRange(
            otio.opentime.RationalTime(0, 24),
            otio.opentime.RationalTime(50, 24)
        )
        mr = otio.schema.ExternalReference(
            available_range=avail_tr,
            target_url="/var/tmp/test.mov"
        )

        cl = otio.schema.Clip(
            name=name + "_pre",
            media_reference=mr,
            source_range=tr,
        )
github PixarAnimationStudios / OpenTimelineIO / contrib / opentimelineio_contrib / adapters / hls_playlist.py View on Github external
def _handle_INF(self, entry, playlist_version, clip):
        # This specifies segment duration and optional title
        info_dict = entry.parsed_tag_value(playlist_version)
        segment_duration = float(info_dict['duration'])
        segment_title = info_dict['title']
        available_range = otio.opentime.TimeRange(
            otio.opentime.RationalTime(0, 1),
            otio.opentime.RationalTime(segment_duration, 1)
        )

        # Push the info to the clip
        clip.media_reference.available_range = available_range
        clip.source_range = available_range
        clip.name = segment_title
github PixarAnimationStudios / OpenTimelineIO / opentimelineio / adapters / pretty_print_string.py View on Github external
def timing_info_as_timecode(ti):
    try:
        return "[{}, {}]".format(
            otio.opentime.to_timecode(ti.start_time),
            otio.opentime.to_timecode(ti.duration),
        )
    except KeyError:
        return "{}"
github PixarAnimationStudios / OpenTimelineIO / contrib / opentimelineio_contrib / adapters / hls_playlist.py View on Github external
# Write out the segment and start the next
            start_fragment = gathered_fragments[0]

            # If the map for this segment was a change, write it
            if map_changed:
                self._add_map_entry(start_fragment)

            # add the entries for the segment. Omit any EXT-X-MAP metadata
            # that may have come in from reading a file (we're updating)
            self._add_entries_for_segment_from_fragments(
                gathered_fragments,
                omit_hls_keys=('EXT-X-MAP'),
                is_iframe_playlist=is_iframe_playlist
            )

            duration_seconds = otio.opentime.to_seconds(gathered_duration)
            segment_durations.append(duration_seconds)

            # in the next iteration, start where we left off
            fragments = fragments[len(gathered_fragments):]

        # Set the max segment duration
        max_duration = round(max(segment_durations))
        self._playlist_tags['EXT-X-TARGETDURATION'] = str(int(max_duration))
github PixarAnimationStudios / OpenTimelineIO / opentimelineio / schema / gap.py View on Github external
# Duration is provided as a convienence for creating a gap of a certain
        # length.  IE: Gap(duration=otio.opentime.RationalTime(300, 24))
        duration=None,
        source_range=None,
        effects=None,
        markers=None,
        metadata=None,
    ):
        if duration and source_range:
            raise RuntimeError(
                "Cannot instantiate with both a source range and a duration."
            )

        if duration:
            source_range = opentime.TimeRange(
                opentime.RationalTime(0, duration.rate),
                duration
            )
        elif source_range is None:
            # if neither is provided, seed TimeRange as an empty Source Range.
            source_range = opentime.TimeRange()

        core.Item.__init__(
            self,
            name=name,
            source_range=source_range,
            effects=effects,
            markers=markers,
            metadata=metadata
        )
github PixarAnimationStudios / OpenTimelineIO / opentimelineio / core / composition.py View on Github external
def trim_child_range(self, child_range):
        if not self.source_range:
            return child_range

        # cropped out entirely
        past_end_time = self.source_range.start_time >= child_range.end_time_exclusive()
        before_start_time = \
            self.source_range.end_time_exclusive() <= child_range.start_time

        if past_end_time or before_start_time:
            return None

        if child_range.start_time < self.source_range.start_time:
            child_range = opentime.range_from_start_end_time(
                self.source_range.start_time,
                child_range.end_time_exclusive()
            )

        if (
            child_range.end_time_exclusive() >
            self.source_range.end_time_exclusive()
        ):
            child_range = opentime.range_from_start_end_time(
                child_range.start_time,
                self.source_range.end_time_exclusive()
            )

        return child_range
github PixarAnimationStudios / OpenTimelineIO / src / opentimelineview / timeline_widget.py View on Github external
def _adjust_scene_size(self):
        scene_range = self.composition.trimmed_range()

        start_time = otio.opentime.to_seconds(scene_range.start_time)
        duration = otio.opentime.to_seconds(scene_range.end_time_exclusive())

        if isinstance(self.composition, otio.schema.Stack):
            # non audio tracks are sorted into one area
            has_video_tracks = any(
                t.kind != otio.schema.TrackKind.Audio
                for t in self.composition
            )
            has_audio_tracks = any(
                t.kind == otio.schema.TrackKind.Audio
                for t in self.composition
            )
        elif isinstance(self.composition, otio.schema.Track):
            has_video_tracks = (
                self.composition.kind != otio.schema.TrackKind.Audio
            )
            has_audio_tracks = (