From bf44622c057fd6d45c8a270ae24ee0f71eb89abc Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 17 Apr 2025 12:55:02 +0200 Subject: [PATCH] Improves thumbnail extraction reliability Ensures thumbnail extraction falls back to the first frame if the initial attempt fails, handling potential issues with seek position calculation or output file creation. This enhances the robustness of the thumbnail creation process. --- .../plugins/publish/extract_thumbnail.py | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/plugins/publish/extract_thumbnail.py b/client/ayon_core/plugins/publish/extract_thumbnail.py index 89bb9a90ab..e5108444f7 100644 --- a/client/ayon_core/plugins/publish/extract_thumbnail.py +++ b/client/ayon_core/plugins/publish/extract_thumbnail.py @@ -498,7 +498,8 @@ class ExtractThumbnail(pyblish.api.InstancePlugin): # For very short videos, just use the first frame # Calculate seek position safely seek_position = 0 - if duration > 0.1: # Only use timestamp calculation for videos longer than 0.1 seconds + # Only use timestamp calculation for videos longer than 0.1 seconds + if duration > 0.1: seek_position = duration * self.duration_split # Build command args @@ -531,13 +532,17 @@ class ExtractThumbnail(pyblish.api.InstancePlugin): run_subprocess(cmd, logger=self.log) # Verify the output file was created - if os.path.exists(output_thumb_file_path) and os.path.getsize(output_thumb_file_path) > 0: + if ( + os.path.exists(output_thumb_file_path) + and os.path.getsize(output_thumb_file_path) > 0 + ): self.log.debug( "Thumbnail created: {}".format(output_thumb_file_path)) return output_thumb_file_path else: self.log.warning( - "Output file was not created or is empty: {}".format(output_thumb_file_path)) + "Output file was not created or is empty: {}".format( + output_thumb_file_path)) # Fallback to extracting the first frame without seeking if "-ss" in cmd_args: @@ -549,11 +554,18 @@ class ExtractThumbnail(pyblish.api.InstancePlugin): # Create new command and try again cmd = get_ffmpeg_tool_args("ffmpeg", *cmd_args) - self.log.debug("Fallback command: {}".format(" ".join(cmd))) + self.log.debug("Fallback command: {}".format( + " ".join(cmd))) run_subprocess(cmd, logger=self.log) - if os.path.exists(output_thumb_file_path) and os.path.getsize(output_thumb_file_path) > 0: - self.log.debug("Fallback thumbnail created: {}".format(output_thumb_file_path)) + if ( + os.path.exists(output_thumb_file_path) + and os.path.getsize(output_thumb_file_path) > 0 + ): + self.log.debug( + "Fallback thumbnail created: {}".format( + output_thumb_file_path) + ) return output_thumb_file_path return None