-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added pre- / post-transcribe hooks to facilitate media essence embedding
Signed-off-by: Tim Lehr <[email protected]>
- Loading branch information
Showing
12 changed files
with
634 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
264 changes: 234 additions & 30 deletions
264
src/otio_aaf_adapter/adapters/aaf_adapter/aaf_writer.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# Copyright Contributors to the OpenTimelineIO project | ||
|
||
import aaf2 | ||
import opentimelineio as otio | ||
|
||
|
||
# Plugin custom hook names | ||
HOOK_PRE_TRANSCRIBE = "otio_aaf_pre_transcribe" | ||
HOOK_POST_TRANSCRIBE = "otio_aaf_post_transcribe" | ||
|
||
def run_pre_transcribe_hook( | ||
timeline: otio.schema.Timeline, | ||
write_filepath: str, | ||
aaf_handle: aaf2.file.AAFFile, | ||
embed_essence: bool, | ||
extra_kwargs: dict | ||
) -> otio.schema.Timeline: | ||
"""This hook runs on write, just before the timeline gets translated to pyaaf2 | ||
data.""" | ||
if HOOK_PRE_TRANSCRIBE in otio.hooks.names(): | ||
extra_kwargs.update({ | ||
"write_filepath": write_filepath, | ||
"aaf_handle": aaf_handle, | ||
"embed_essence": embed_essence, | ||
}) | ||
return otio.hooks.run(HOOK_PRE_TRANSCRIBE, timeline, extra_kwargs) | ||
return timeline | ||
|
||
|
||
def run_post_transcribe_hook( | ||
timeline: otio.schema.Timeline, | ||
write_filepath: str, | ||
aaf_handle: aaf2.file.AAFFile, | ||
embed_essence: bool, | ||
extra_kwargs: dict | ||
) -> otio.schema.Timeline: | ||
"""This hook runs on write, just after the timeline gets translated to pyaaf2 | ||
data.""" | ||
if HOOK_POST_TRANSCRIBE in otio.hooks.names(): | ||
extra_kwargs.update({ | ||
"write_filepath": write_filepath, | ||
"aaf_handle": aaf_handle, | ||
"embed_essence": embed_essence, | ||
}) | ||
return otio.hooks.run(HOOK_POST_TRANSCRIBE, timeline, extra_kwargs) | ||
return timeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"OTIO_SCHEMA" : "PluginManifest.1", | ||
"hook_scripts" : [ | ||
{ | ||
"OTIO_SCHEMA" : "HookScript.1", | ||
"name" : "pre_aaf_transcribe_hook", | ||
"execution_scope" : "in process", | ||
"filepath" : "pre_aaf_transcribe_hook.py" | ||
}, | ||
{ | ||
"OTIO_SCHEMA" : "HookScript.1", | ||
"name" : "post_aaf_transcribe_hook", | ||
"execution_scope" : "in process", | ||
"filepath" : "post_aaf_transcribe_hook.py" | ||
} | ||
], | ||
"hooks" : { | ||
"otio_aaf_pre_transcribe": ["pre_aaf_transcribe_hook"], | ||
"otio_aaf_post_transcribe": ["post_aaf_transcribe_hook"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Example hook that runs post-transcription on a write operation. | ||
This hook is useful to clean up temporary files or metadata post-write. | ||
""" | ||
from otio_aaf_adapter.adapters.aaf_adapter.aaf_writer import AAFAdapterError | ||
|
||
|
||
def hook_function(in_timeline, argument_map=None): | ||
if argument_map.get("test_post_hook_raise", False): | ||
raise AAFAdapterError() | ||
|
||
if not argument_map.get("embed_essence", False): | ||
# no essence embedding requested, skip the hook | ||
return in_timeline | ||
|
||
for clip in in_timeline.find_clips(): | ||
# reset target URL to pre-conversion media, remove metadata | ||
original_url = clip.media_reference.metadata.pop("original_target_url") | ||
if original_url: | ||
clip.media_reference.target_url = original_url | ||
|
||
return in_timeline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Example hook that runs pre-transcription on a write operation. | ||
This can be useful for just-in-time transcoding of media references to DNX data / | ||
WAVE audio files. | ||
""" | ||
import os | ||
from pathlib import Path | ||
from otio_aaf_adapter.adapters.aaf_adapter.aaf_writer import AAFAdapterError | ||
|
||
|
||
def hook_function(in_timeline, argument_map=None): | ||
if argument_map.get("test_pre_hook_raise", False): | ||
raise AAFAdapterError() | ||
|
||
if not argument_map.get("embed_essence", False): | ||
# no essence embedding requested, skip the hook | ||
return in_timeline | ||
|
||
for clip in in_timeline.find_clips(): | ||
# mock convert video media references, this could be done with ffmpeg | ||
if Path(clip.media_reference.target_url).suffix == ".mov": | ||
converted_url = Path(clip.media_reference.target_url).with_suffix(".dnx") | ||
clip.media_reference.metadata[ | ||
"original_target_url" | ||
] = clip.media_reference.target_url | ||
clip.media_reference.target_url = os.fspath(converted_url) | ||
|
||
return in_timeline |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.