Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 32 additions & 12 deletions contrib/opentimelineio_contrib/adapters/extern_rv.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ def _create_media_reference(item, src, track_kind=None):
src.setMedia(media)
return True

elif isinstance(item.media_reference, otio.schema.ImageSequenceReference):
frame_sub = "%0{n}d".format(
n=item.media_reference.frame_zero_padding
)

media = [
str(item.media_reference.abstract_target_url(symbol=frame_sub))
]

src.setMedia(media)

return True

elif isinstance(item.media_reference, otio.schema.GeneratorReference):
if item.media_reference.generator_kind == "SMPTEBars":
kind = "smptebars"
Expand Down Expand Up @@ -291,20 +304,27 @@ def _write_item(it, to_session, track_kind=None):
)
)

# because OTIO has no global concept of FPS, the rate of the duration is
# used as the rate for the range of the source.
# RationalTime.value_rescaled_to returns the time value of the object in
# time rate of the argument.
src.setCutIn(
range_to_read.start_time.value_rescaled_to(
range_to_read.duration
in_frame = out_frame = None
if hasattr(it, "media_reference") and it.media_reference:
if isinstance(it.media_reference, otio.schema.ImageSequenceReference):
in_frame, out_frame = it.media_reference.frame_range_for_time_range(
range_to_read
)

if not in_frame and not out_frame:
# because OTIO has no global concept of FPS, the rate of the duration
# is used as the rate for the range of the source.
in_frame = otio.opentime.to_frames(
range_to_read.start_time,
rate=range_to_read.duration.rate
)
)
src.setCutOut(
range_to_read.end_time_inclusive().value_rescaled_to(
range_to_read.duration
out_frame = otio.opentime.to_frames(
range_to_read.end_time_inclusive(),
rate=range_to_read.duration.rate
)
)

src.setCutIn(in_frame)
src.setCutOut(out_frame)
src.setFPS(range_to_read.duration.rate)

# if the media reference is missing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"OTIO_SCHEMA": "Timeline.1",
"metadata": {},
"name": "",
"global_start_time": null,
"tracks": {
"OTIO_SCHEMA": "Stack.1",
"metadata": {},
"name": "tracks",
"source_range": null,
"effects": [],
"markers": [],
"children": [
{
"OTIO_SCHEMA": "Track.1",
"metadata": {},
"name": "V",
"source_range": null,
"effects": [],
"markers": [],
"children": [
{
"OTIO_SCHEMA": "Clip.1",
"metadata": {
"cmx_3600": {
"reel": "sample_sequence"
}
},
"name": "sample_sequence",
"source_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 30.0
},
"start_time": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 86410.0
}
},
"effects": [],
"markers": [],
"media_reference": {
"OTIO_SCHEMA": "ImageSequenceReference.1",
"metadata": {},
"name": "",
"available_range": {
"OTIO_SCHEMA": "TimeRange.1",
"duration": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 50.0
},
"start_time": {
"OTIO_SCHEMA": "RationalTime.1",
"rate": 24.0,
"value": 86400.0
}
},
"target_url_base": "./sample_sequence/",
"name_prefix": "sample_sequence.",
"name_suffix": ".exr",
"start_frame": 1001,
"frame_step": 1,
"rate": 24.0,
"frame_zero_padding": 4,
"missing_frame_policy": "error"
}
}
],
"kind": "Video"
}
]
}
}
65 changes: 46 additions & 19 deletions contrib/opentimelineio_contrib/adapters/tests/test_rvsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
BASELINE_TRANSITION_PATH = os.path.join(SAMPLE_DATA_DIR, "transition_test.rv")
METADATA_EXAMPLE_PATH = os.path.join(SAMPLE_DATA_DIR, "rv_metadata.otio")
METADATA_BASELINE_PATH = os.path.join(SAMPLE_DATA_DIR, "rv_metadata.rv")
IMAGE_SEQUENCE_EXAMPLE_PATH = os.path.join(
SAMPLE_DATA_DIR,
"image_sequence_example.otio"
)


SAMPLE_DATA = """{
Expand Down Expand Up @@ -466,14 +470,21 @@
"RV Adapter does not work in python 3."
)
class RVSessionAdapterReadTest(unittest.TestCase):
def setUp(self):
fd, self.tmp_path = tempfile.mkstemp(suffix=".rv", text=True)

# Close file descriptor to avoid leak. We only need the tmp_path.
os.close(fd)

def tearDown(self):
os.unlink(self.tmp_path)

def test_basic_rvsession_read(self):
timeline = otio.adapters.read_from_file(SCREENING_EXAMPLE_PATH)
tmp_path = tempfile.mkstemp(suffix=".rv", text=True)[1]

otio.adapters.write_to_file(timeline, tmp_path)
self.assertTrue(os.path.exists(tmp_path))
otio.adapters.write_to_file(timeline, self.tmp_path)

with open(tmp_path) as fo:
with open(self.tmp_path) as fo:
test_data = fo.read()

with open(BASELINE_PATH) as fo:
Expand All @@ -484,12 +495,11 @@ def test_basic_rvsession_read(self):

def test_transition_rvsession_read(self):
timeline = otio.adapters.read_from_file(TRANSITION_EXAMPLE_PATH)
tmp_path = tempfile.mkstemp(suffix=".rv", text=True)[1]

otio.adapters.write_to_file(timeline, tmp_path)
self.assertTrue(os.path.exists(tmp_path))
otio.adapters.write_to_file(timeline, self.tmp_path)
self.assertTrue(os.path.exists(self.tmp_path))

with open(tmp_path) as fo:
with open(self.tmp_path) as fo:
test_data = fo.read()

with open(BASELINE_TRANSITION_PATH) as fo:
Expand All @@ -498,16 +508,35 @@ def test_transition_rvsession_read(self):
self.maxDiff = None
self.assertMultiLineEqual(baseline_data, test_data)

def test_image_sequence_example(self):
# SETUP
timeline = otio.adapters.read_from_file(IMAGE_SEQUENCE_EXAMPLE_PATH)

# EXERCISE
otio.adapters.write_to_file(timeline, self.tmp_path)

# VERIFY
self.assertTrue(os.path.exists(self.tmp_path))

with open(self.tmp_path) as f:
rv_session = f.read()

self.assertEqual(
rv_session.count(
'string movie = "./sample_sequence/sample_sequence.%04d.exr"'
),
1
)

def test_transition_rvsession_covers_entire_shots(self):
# SETUP
timeline = otio.adapters.read_from_string(SAMPLE_DATA, "otio_json")
tmp_path = tempfile.mkstemp(suffix=".rv", text=True)[1]

# EXERCISE
otio.adapters.write_to_file(timeline, tmp_path)
otio.adapters.write_to_file(timeline, self.tmp_path)

# VERIFY
with open(tmp_path, "r") as f:
with open(self.tmp_path, "r") as f:
rv_session = f.read()

self.assertEqual(rv_session.count('movie = "blank'), 1)
Expand All @@ -516,13 +545,12 @@ def test_transition_rvsession_covers_entire_shots(self):
def test_audio_video_tracks(self):
# SETUP
timeline = otio.adapters.read_from_string(AUDIO_VIDEO_SAMPLE_DATA, "otio_json")
tmp_path = tempfile.mkstemp(suffix=".rv", text=True)[1]

# EXERCISE
otio.adapters.write_to_file(timeline, tmp_path)
otio.adapters.write_to_file(timeline, self.tmp_path)

# VERIFY
self.assertTrue(os.path.exists(tmp_path))
self.assertTrue(os.path.exists(self.tmp_path))

audio_video_source = (
'string movie = '
Expand All @@ -531,7 +559,7 @@ def test_audio_video_tracks(self):
' "/path/to/audio.wav" ]'
)

with open(tmp_path, "r") as f:
with open(self.tmp_path, "r") as f:
rv_session = f.read()

self.assertEqual(rv_session.count("string movie"), 2)
Expand All @@ -544,13 +572,12 @@ def test_nested_stack(self):
NESTED_STACK_SAMPLE_DATA,
"otio_json"
)
tmp_path = tempfile.mkstemp(suffix=".rv", text=True)[1]

# EXERCISE
otio.adapters.write_to_file(timeline, tmp_path)
otio.adapters.write_to_file(timeline, self.tmp_path)

# VERIFY
self.assertTrue(os.path.exists(tmp_path))
self.assertTrue(os.path.exists(self.tmp_path))

audio_video_source = (
'string movie = '
Expand All @@ -562,7 +589,7 @@ def test_nested_stack(self):
'string movie = "/path/to/some/video.mov"'
)

with open(tmp_path, "r") as f:
with open(self.tmp_path, "r") as f:
rv_session = f.read()
self.assertEqual(rv_session.count(video_source), 2)
self.assertEqual(rv_session.count(audio_video_source), 2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ def _create_media_reference(item, track_kind=None):
# Appending blank to media promotes name of audio file in RV
media.append(blank)

return media
elif isinstance(item.media_reference,
otio.schema.ImageSequenceReference):
frame_sub = "%0{n}d".format(
n=item.media_reference.frame_zero_padding
)

media = [
str(item.media_reference.abstract_target_url(symbol=frame_sub))
]

return media
elif isinstance(item.media_reference, otio.schema.GeneratorReference):
if item.media_reference.generator_kind == "SMPTEBars":
Expand Down Expand Up @@ -250,19 +261,28 @@ def _create_item(it, track_kind=None):
if hasattr(it, "media_reference") and it.media_reference:
_add_metadata_to_node(it.media_reference, src)

# because OTIO has no global concept of FPS, the rate of the duration is
# used as the rate for the range of the source.
# RationalTime.value_rescaled_to returns the time value of the object in
# time rate of the argument.
cut_in = range_to_read.start_time.value_rescaled_to(
range_to_read.duration
)
commands.setIntProperty(src + ".cut.in", [int(cut_in)])
in_frame = out_frame = None
if hasattr(it, "media_reference") and it.media_reference:
if isinstance(it.media_reference, otio.schema.ImageSequenceReference):
in_frame, out_frame = \
it.media_reference.frame_range_for_time_range(
range_to_read
)

if not in_frame and not out_frame:
# because OTIO has no global concept of FPS, the rate of the duration
# is used as the rate for the range of the source.
in_frame = otio.opentime.to_frames(
range_to_read.start_time,
rate=range_to_read.duration.rate
)
out_frame = otio.opentime.to_frames(
range_to_read.end_time_inclusive(),
rate=range_to_read.duration.rate
)

cut_out = range_to_read.end_time_inclusive().value_rescaled_to(
range_to_read.duration
)
commands.setIntProperty(src + ".cut.out", [int(cut_out)])
commands.setIntProperty(src + ".cut.in", [in_frame])
commands.setIntProperty(src + ".cut.out", [out_frame])

commands.setFloatProperty(src + ".group.fps",
[float(range_to_read.duration.rate)])
Expand Down
15 changes: 15 additions & 0 deletions docs/tutorials/otio-serialized-schema-only-fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ parameters:
- *name*
- *parameters*

### ImageSequenceReference.1

parameters:
- *available_range*
- *frame_step*
- *frame_zero_padding*
- *metadata*
- *missing_frame_policy*
- *name*
- *name_prefix*
- *name_suffix*
- *rate*
- *start_frame*
- *target_url_base*

### LinearTimeWarp.1

parameters:
Expand Down
Loading