Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_timerange(self):
tr = otio.opentime.TimeRange()
self.check_against_baseline(tr, "empty_timerange")
def test_trimmed_range(self):
it = otio.core.Item()
with self.assertRaises(NotImplementedError):
it.trimmed_range()
tr = otio.opentime.TimeRange(
otio.opentime.RationalTime(1, 1),
otio.opentime.RationalTime(10, 1)
)
it2 = otio.core.Item(source_range=tr)
self.assertEqual(it2.trimmed_range(), tr)
self.assertIsNot(it2.trimmed_range(), tr)
def test_serialize_time(self):
rt = otio.opentime.RationalTime(15, 24)
encoded = otio.adapters.otio_json.write_to_string(rt)
decoded = otio.adapters.otio_json.read_from_string(encoded)
self.assertEqual(rt, decoded)
rt_dur = otio.opentime.RationalTime(10, 20)
tr = otio.opentime.TimeRange(rt, rt_dur)
encoded = otio.adapters.otio_json.write_to_string(tr)
decoded = otio.adapters.otio_json.read_from_string(encoded)
self.assertEqual(tr, decoded)
tt = otio.opentime.TimeTransform(rt, scale=1.5)
encoded = otio.adapters.otio_json.write_to_string(tt)
decoded = otio.adapters.otio_json.read_from_string(encoded)
self.assertEqual(tt, decoded)
def test_compare(self):
start_time1 = otio.opentime.RationalTime(18, 24)
duration1 = otio.opentime.RationalTime(7, 24)
tr1 = otio.opentime.TimeRange(start_time1, duration1)
start_time2 = otio.opentime.RationalTime(18, 24)
duration2 = otio.opentime.RationalTime(14, 48)
tr2 = otio.opentime.TimeRange(start_time2, duration2)
self.assertEqual(tr1, tr2)
self.assertFalse(tr1 != tr2)
start_time3 = otio.opentime.RationalTime(20, 24)
duration3 = otio.opentime.RationalTime(3, 24)
tr3 = otio.opentime.TimeRange(start_time3, duration3)
self.assertNotEqual(tr1, tr3)
self.assertFalse(tr1 == tr3)
# Media Reference: [100-199]
# here are some times in the top-level coordinate system
zero = otio.opentime.RationalTime(0, 24)
one = otio.opentime.RationalTime(1, 24)
fifty = otio.opentime.RationalTime(50, 24)
ninetynine = otio.opentime.RationalTime(99, 24)
onehundred = otio.opentime.RationalTime(100, 24)
top_level_range = otio.opentime.TimeRange(
start_time=zero, duration=onehundred)
# here are some times in the media-level coordinate system
first_frame = otio.opentime.RationalTime(100, 24)
middle = otio.opentime.RationalTime(150, 24)
last = otio.opentime.RationalTime(199, 24)
media_range = otio.opentime.TimeRange(
start_time=first_frame, duration=onehundred)
timeline = otio.schema.Timeline()
stack = timeline.tracks
track = otio.schema.Track()
clip = otio.schema.Clip()
media = otio.schema.MissingReference()
media.available_range = media_range
clip.media_reference = media
track.append(clip)
stack.append(track)
self.assertIs(track, clip.parent())
self.assertIs(stack, track.parent())
# the clip and track should auto-size to fit the media, since we
def test_trim_child_range(self):
for st in [
otio.schema.Track(name="foo"),
otio.schema.Stack(name="foo")
]:
st.source_range = otio.opentime.TimeRange(
start_time=otio.opentime.RationalTime(value=100, rate=24),
duration=otio.opentime.RationalTime(value=50, rate=24)
)
r = otio.opentime.TimeRange(
start_time=otio.opentime.RationalTime(value=110, rate=24),
duration=otio.opentime.RationalTime(value=30, rate=24)
)
self.assertEqual(st.trim_child_range(r), r)
r = otio.opentime.TimeRange(
start_time=otio.opentime.RationalTime(value=0, rate=24),
duration=otio.opentime.RationalTime(value=30, rate=24)
)
self.assertEqual(st.trim_child_range(r), None)
r = otio.opentime.TimeRange(
start_time=otio.opentime.RationalTime(value=1000, rate=24),
duration=otio.opentime.RationalTime(value=30, rate=24)
def test_compare(self):
start_time1 = otio.opentime.RationalTime(18, 24)
duration1 = otio.opentime.RationalTime(7, 24)
tr1 = otio.opentime.TimeRange(start_time1, duration1)
start_time2 = otio.opentime.RationalTime(18, 24)
duration2 = otio.opentime.RationalTime(14, 48)
tr2 = otio.opentime.TimeRange(start_time2, duration2)
self.assertEqual(tr1, tr2)
self.assertFalse(tr1 != tr2)
start_time3 = otio.opentime.RationalTime(20, 24)
duration3 = otio.opentime.RationalTime(3, 24)
tr3 = otio.opentime.TimeRange(start_time3, duration3)
self.assertNotEqual(tr1, tr3)
self.assertFalse(tr1 == tr3)
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)
)
except ValueError:
raise ValueError(
"item: {} is not in composition: {}".format(
item,
self
)
)
previous, next_item = None, None
# look before index
if index == 0:
if insert_gap == NeighborGapPolicy.around_transitions:
if isinstance(item, transition.Transition):
previous = gap.Gap(
source_range=opentime.TimeRange(duration=item.in_offset))
elif index > 0:
previous = self[index - 1]
if index == len(self) - 1:
if insert_gap == NeighborGapPolicy.around_transitions:
if isinstance(item, transition.Transition):
next_item = gap.Gap(
source_range=opentime.TimeRange(duration=item.out_offset))
elif index < len(self) - 1:
next_item = self[index + 1]
return collections.namedtuple('neighbors', ('previous', 'next'))(
previous,
next_item
)
"default=noprint_wrappers=1:nokey=1",
media_path
]
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = proc.communicate()
if proc.returncode != 0:
raise FFProbeFailedError(
"FFProbe Failed with error: {0}, output: {1}".format(
err, out
)
)
available_range = otio.opentime.TimeRange(
otio.opentime.RationalTime(0, 1).rescaled_to(fps),
otio.opentime.RationalTime(float(out), 1).rescaled_to(fps)
)
_MEDIA_RANGE_MAP[media_path] = available_range
return available_range