From 1bdd64ae3de81473796ed52ac3f59dde47fca55b Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:03:17 +0200 Subject: [PATCH 1/4] allow path to python file --- client/ayon_core/pipeline/publish/lib.py | 37 +++++++++++++----------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/client/ayon_core/pipeline/publish/lib.py b/client/ayon_core/pipeline/publish/lib.py index fb84417730..ddb1c46def 100644 --- a/client/ayon_core/pipeline/publish/lib.py +++ b/client/ayon_core/pipeline/publish/lib.py @@ -243,32 +243,35 @@ def publish_plugins_discover( for path in paths: path = os.path.normpath(path) - if not os.path.isdir(path): - continue + filenames = [] + if os.path.isdir(path): + filenames.extend( + name + for name in os.listdir(path) + if ( + os.path.isfile(os.path.join(path, name)) + and not name.startswith("_") + ) + ) + else: + filenames.append(os.path.basename(path)) + path = os.path.dirname(path) - for fname in os.listdir(path): - if fname.startswith("_"): - continue - - abspath = os.path.join(path, fname) - - if not os.path.isfile(abspath): - continue - - mod_name, mod_ext = os.path.splitext(fname) - - if mod_ext != ".py": + for filename in filenames: + mod_name, mod_ext = os.path.splitext(filename) + if mod_ext.lower() != ".py": continue + filepath = os.path.join(path, filename) try: module = import_filepath( - abspath, mod_name, sys_module_name=mod_name) + filepath, mod_name, sys_module_name=mod_name except Exception as err: # noqa: BLE001 # we need broad exception to catch all possible errors. - result.crashed_file_paths[abspath] = sys.exc_info() + result.crashed_file_paths[filepath] = sys.exc_info() - log.debug('Skipped: "%s" (%s)', mod_name, err) + log.debug('Skipped: "%s" (%s)', filepath, err) continue for plugin in pyblish.plugin.plugins_from_module(module): From c398e1fca35c5c379acb53b1c47bce8a493affb9 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:03:37 +0200 Subject: [PATCH 2/4] hash dirpath for sys modules --- client/ayon_core/pipeline/publish/lib.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/publish/lib.py b/client/ayon_core/pipeline/publish/lib.py index ddb1c46def..c0b138c7f2 100644 --- a/client/ayon_core/pipeline/publish/lib.py +++ b/client/ayon_core/pipeline/publish/lib.py @@ -5,6 +5,7 @@ import sys import inspect import copy import warnings +import hashlib import xml.etree.ElementTree from typing import TYPE_CHECKING, Optional, Union, List @@ -257,15 +258,18 @@ def publish_plugins_discover( filenames.append(os.path.basename(path)) path = os.path.dirname(path) + dirpath_hash = hashlib.md5(path.encode("utf-8")).hexdigest() for filename in filenames: mod_name, mod_ext = os.path.splitext(filename) if mod_ext.lower() != ".py": continue filepath = os.path.join(path, filename) + sys_module_name = f"{dirpath_hash}.{mod_name}" try: module = import_filepath( - filepath, mod_name, sys_module_name=mod_name + filepath, mod_name, sys_module_name=sys_module_name + ) except Exception as err: # noqa: BLE001 # we need broad exception to catch all possible errors. From cdb719494ef86728f22440e137320e2aa91c6216 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Fri, 25 Jul 2025 17:19:26 +0200 Subject: [PATCH 3/4] use same name for both sys module and module --- client/ayon_core/pipeline/publish/lib.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/pipeline/publish/lib.py b/client/ayon_core/pipeline/publish/lib.py index c0b138c7f2..d360526024 100644 --- a/client/ayon_core/pipeline/publish/lib.py +++ b/client/ayon_core/pipeline/publish/lib.py @@ -260,15 +260,15 @@ def publish_plugins_discover( dirpath_hash = hashlib.md5(path.encode("utf-8")).hexdigest() for filename in filenames: - mod_name, mod_ext = os.path.splitext(filename) - if mod_ext.lower() != ".py": + basename, ext = os.path.splitext(filename) + if ext.lower() != ".py": continue filepath = os.path.join(path, filename) - sys_module_name = f"{dirpath_hash}.{mod_name}" + module_name = f"{dirpath_hash}.{basename}" try: module = import_filepath( - filepath, mod_name, sys_module_name=sys_module_name + filepath, module_name, sys_module_name=module_name ) except Exception as err: # noqa: BLE001 From bfc82a07fd58914933f7d1757dc48f3a6e1601c8 Mon Sep 17 00:00:00 2001 From: "robin@ynput.io" Date: Mon, 28 Jul 2025 11:30:57 -0400 Subject: [PATCH 4/4] Detect rounding issues in media available_range when extracting (OTIO). --- client/ayon_core/pipeline/editorial.py | 4 ++ .../publish/extract_otio_audio_tracks.py | 9 +++++ .../plugins/publish/extract_otio_review.py | 39 +++++++++++++++---- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/pipeline/editorial.py b/client/ayon_core/pipeline/editorial.py index 8b6cfc52f1..b553fae3fb 100644 --- a/client/ayon_core/pipeline/editorial.py +++ b/client/ayon_core/pipeline/editorial.py @@ -7,6 +7,10 @@ import opentimelineio as otio from opentimelineio import opentime as _ot +# https://github.com/AcademySoftwareFoundation/OpenTimelineIO/issues/1822 +OTIO_EPSILON = 1e-9 + + def otio_range_to_frame_range(otio_range): start = _ot.to_frames( otio_range.start_time, otio_range.start_time.rate) diff --git a/client/ayon_core/plugins/publish/extract_otio_audio_tracks.py b/client/ayon_core/plugins/publish/extract_otio_audio_tracks.py index 472694d334..2aec4a5415 100644 --- a/client/ayon_core/plugins/publish/extract_otio_audio_tracks.py +++ b/client/ayon_core/plugins/publish/extract_otio_audio_tracks.py @@ -7,6 +7,7 @@ from ayon_core.lib import ( get_ffmpeg_tool_args, run_subprocess ) +from ayon_core.pipeline import editorial class ExtractOtioAudioTracks(pyblish.api.ContextPlugin): @@ -172,6 +173,14 @@ class ExtractOtioAudioTracks(pyblish.api.ContextPlugin): clip_start = otio_clip.source_range.start_time fps = clip_start.rate conformed_av_start = media_av_start.rescaled_to(fps) + + # Avoid rounding issue on media available range. + if clip_start.almost_equal( + conformed_av_start, + editorial.OTIO_EPSILON + ): + conformed_av_start = clip_start + # ffmpeg ignores embedded tc start = clip_start - conformed_av_start duration = otio_clip.source_range.duration diff --git a/client/ayon_core/plugins/publish/extract_otio_review.py b/client/ayon_core/plugins/publish/extract_otio_review.py index f217be551c..74cf45e474 100644 --- a/client/ayon_core/plugins/publish/extract_otio_review.py +++ b/client/ayon_core/plugins/publish/extract_otio_review.py @@ -23,7 +23,11 @@ from ayon_core.lib import ( get_ffmpeg_tool_args, run_subprocess, ) -from ayon_core.pipeline import publish +from ayon_core.pipeline import ( + KnownPublishError, + editorial, + publish, +) class ExtractOTIOReview( @@ -97,8 +101,11 @@ class ExtractOTIOReview( # skip instance if no reviewable data available if ( - not isinstance(otio_review_clips[0], otio.schema.Clip) - and len(otio_review_clips) == 1 + len(otio_review_clips) == 1 + and ( + not isinstance(otio_review_clips[0], otio.schema.Clip) + or otio_review_clips[0].media_reference.is_missing_reference + ) ): self.log.warning( "Instance `{}` has nothing to process".format(instance)) @@ -248,7 +255,7 @@ class ExtractOTIOReview( # Single video way. # Extraction via FFmpeg. - else: + elif hasattr(media_ref, "target_url"): path = media_ref.target_url # Set extract range from 0 (FFmpeg ignores # embedded timecode). @@ -370,6 +377,13 @@ class ExtractOTIOReview( avl_start = avl_range.start_time + # Avoid rounding issue on media available range. + if start.almost_equal( + avl_start, + editorial.OTIO_EPSILON + ): + avl_start = start + # An additional gap is required before the available # range to conform source start point and head handles. if start < avl_start: @@ -388,6 +402,14 @@ class ExtractOTIOReview( # (media duration is shorter then clip requirement). end_point = start + duration avl_end_point = avl_range.end_time_exclusive() + + # Avoid rounding issue on media available range. + if end_point.almost_equal( + avl_end_point, + editorial.OTIO_EPSILON + ): + avl_end_point = end_point + if end_point > avl_end_point: gap_duration = end_point - avl_end_point duration -= gap_duration @@ -444,7 +466,7 @@ class ExtractOTIOReview( command = get_ffmpeg_tool_args("ffmpeg") input_extension = None - if sequence: + if sequence is not None: input_dir, collection, sequence_fps = sequence in_frame_start = min(collection.indexes) @@ -478,7 +500,7 @@ class ExtractOTIOReview( "-i", input_path ]) - elif video: + elif video is not None: video_path, otio_range = video frame_start = otio_range.start_time.value input_fps = otio_range.start_time.rate @@ -496,7 +518,7 @@ class ExtractOTIOReview( "-i", video_path ]) - elif gap: + elif gap is not None: sec_duration = frames_to_seconds(gap, self.actual_fps) # form command for rendering gap files @@ -510,6 +532,9 @@ class ExtractOTIOReview( "-tune", "stillimage" ]) + else: + raise KnownPublishError("Sequence, video or gap is required.") + if video or sequence: command.extend([ "-vf", f"scale={self.to_width}:{self.to_height}:flags=lanczos",