From 18e882fc4206e07247aa0c409e944bb9584e9a5f Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:10:43 +0200 Subject: [PATCH 1/8] otio burnin script can have defined input arguments and first frame --- openpype/scripts/otio_burnin.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/openpype/scripts/otio_burnin.py b/openpype/scripts/otio_burnin.py index 5e2a22f1b5..dbc5272f13 100644 --- a/openpype/scripts/otio_burnin.py +++ b/openpype/scripts/otio_burnin.py @@ -14,7 +14,7 @@ ffprobe_path = openpype.lib.get_ffmpeg_tool_path("ffprobe") FFMPEG = ( - '"{}" -i "%(input)s" %(filters)s %(args)s%(output)s' + '"{}"%(input_args)s -i "%(input)s" %(filters)s %(args)s%(output)s' ).format(ffmpeg_path) FFPROBE = ( @@ -121,10 +121,18 @@ class ModifiedBurnins(ffmpeg_burnins.Burnins): 'font_size': 42 } - def __init__(self, source, streams=None, options_init=None): + def __init__( + self, source, streams=None, options_init=None, first_frame=None + ): if not streams: streams = _streams(source) + input_args = [] + if first_frame: + input_args.append("-start_number {}".format(first_frame)) + + self.input_args = input_args + super().__init__(source, streams) if options_init: @@ -289,7 +297,12 @@ class ModifiedBurnins(ffmpeg_burnins.Burnins): if self.filter_string: filters = '-vf "{}"'.format(self.filter_string) + input_args = "" + if self.input_args: + input_args = " {}".format(" ".join(self.input_args)) + return (FFMPEG % { + 'input_args': input_args, 'input': self.source, 'output': output, 'args': '%s ' % args if args else '', From ba44eb5acd54ad4dc436cb0df30f1bb9780334c5 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:11:14 +0200 Subject: [PATCH 2/8] passed json may have more data about first frame and full input path --- openpype/scripts/otio_burnin.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/openpype/scripts/otio_burnin.py b/openpype/scripts/otio_burnin.py index dbc5272f13..6dcf00e97c 100644 --- a/openpype/scripts/otio_burnin.py +++ b/openpype/scripts/otio_burnin.py @@ -383,7 +383,8 @@ def example(input_path, output_path): def burnins_from_data( input_path, output_path, data, - codec_data=None, options=None, burnin_values=None, overwrite=True + codec_data=None, options=None, burnin_values=None, overwrite=True, + full_input_path=None, first_frame=None ): """This method adds burnins to video/image file based on presets setting. @@ -440,8 +441,11 @@ def burnins_from_data( "shot": "sh0010" } """ + streams = None + if full_input_path: + streams = _streams(full_input_path) - burnin = ModifiedBurnins(input_path, options_init=options) + burnin = ModifiedBurnins(input_path, streams, options, first_frame) frame_start = data.get("frame_start") frame_end = data.get("frame_end") @@ -604,6 +608,8 @@ if __name__ == "__main__": in_data["burnin_data"], codec_data=in_data.get("codec"), options=in_data.get("options"), - burnin_values=in_data.get("values") + burnin_values=in_data.get("values"), + full_input_path=in_data.get("full_input_path"), + first_frame=in_data.get("first_frame") ) print("* Burnin script has finished") From 4db9d1de69ec7ada8ba10caf3fc9203deec6e4b6 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:16:43 +0200 Subject: [PATCH 3/8] is_sequence is defined by representation "files" value --- openpype/plugins/publish/extract_burnin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openpype/plugins/publish/extract_burnin.py b/openpype/plugins/publish/extract_burnin.py index e266c39714..a53036d1a9 100644 --- a/openpype/plugins/publish/extract_burnin.py +++ b/openpype/plugins/publish/extract_burnin.py @@ -461,10 +461,11 @@ class ExtractBurnin(openpype.api.Extractor): None: This is processing method. """ # TODO we should find better way to know if input is sequence - is_sequence = ( - "sequence" in new_repre["tags"] - and isinstance(new_repre["files"], (tuple, list)) - ) + input_filenames = new_repre["files"] + is_sequence = False + if isinstance(input_filenames, (tuple, list)): + if len(input_filenames) > 1: + is_sequence = True if is_sequence: input_filename = new_repre["sequence_file"] else: From f5e6e07094274585a491ee47fa352fb5f9a43b7a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:19:45 +0200 Subject: [PATCH 4/8] seuqence and single file processing is more secure --- openpype/plugins/publish/extract_burnin.py | 36 ++++++++++------------ 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/openpype/plugins/publish/extract_burnin.py b/openpype/plugins/publish/extract_burnin.py index a53036d1a9..a93a3b21bb 100644 --- a/openpype/plugins/publish/extract_burnin.py +++ b/openpype/plugins/publish/extract_burnin.py @@ -466,28 +466,27 @@ class ExtractBurnin(openpype.api.Extractor): if isinstance(input_filenames, (tuple, list)): if len(input_filenames) > 1: is_sequence = True - if is_sequence: - input_filename = new_repre["sequence_file"] - else: - input_filename = new_repre["files"] - - filepart_start, ext = os.path.splitext(input_filename) - dir_path, basename = os.path.split(filepart_start) if is_sequence: - # NOTE modified to keep name when multiple dots are in name - basename_parts = basename.split(".") - frame_part = basename_parts.pop(-1) + collections, _ = clique.assemble(input_filenames) + if not collections: + is_sequence = False + else: + input_filename = new_repre["sequence_file"] + repre_files = [] - basename_start = ".".join(basename_parts) + filename_suffix - new_basename = ".".join((basename_start, frame_part)) - output_filename = new_basename + ext + if not is_sequence: + input_filename = input_filenames + if isinstance(input_filename, (tuple, list)): + input_filename = input_filename[0] - else: + filepart_start, ext = os.path.splitext(input_filename) + dir_path, basename = os.path.split(filepart_start) output_filename = basename + filename_suffix + ext + if dir_path: + output_filename = os.path.join(dir_path, output_filename) - if dir_path: - output_filename = os.path.join(dir_path, output_filename) + repre_files = output_filename stagingdir = new_repre["stagingDir"] full_input_path = os.path.join( @@ -499,6 +498,7 @@ class ExtractBurnin(openpype.api.Extractor): temp_data["full_input_path"] = full_input_path temp_data["full_output_path"] = full_output_path + new_repre["files"] = repre_files self.log.debug("full_input_path: {}".format(full_input_path)) self.log.debug("full_output_path: {}".format(full_output_path)) @@ -506,17 +506,13 @@ class ExtractBurnin(openpype.api.Extractor): # Prepare full paths to input files and filenames for reprensetation full_input_paths = [] if is_sequence: - repre_files = [] for frame_index in range(1, temp_data["duration"] + 1): - repre_files.append(output_filename % frame_index) full_input_paths.append(full_input_path % frame_index) else: full_input_paths.append(full_input_path) - repre_files = output_filename temp_data["full_input_paths"] = full_input_paths - new_repre["files"] = repre_files def prepare_repre_data(self, instance, repre, burnin_data, temp_data): """Prepare data for representation. From 18248d1ed45d6ea4ee367a39b6f72582034ae33d Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:20:33 +0200 Subject: [PATCH 5/8] concatenate output_filename using found collection of files --- openpype/plugins/publish/extract_burnin.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/openpype/plugins/publish/extract_burnin.py b/openpype/plugins/publish/extract_burnin.py index a93a3b21bb..d926d5aa2a 100644 --- a/openpype/plugins/publish/extract_burnin.py +++ b/openpype/plugins/publish/extract_burnin.py @@ -3,6 +3,7 @@ import re import json import copy import tempfile +import clique import openpype import openpype.api @@ -473,7 +474,17 @@ class ExtractBurnin(openpype.api.Extractor): is_sequence = False else: input_filename = new_repre["sequence_file"] + collection = collections[0] + indexes = list(collection.indexes) + padding = len(str(max(indexes))) + head = collection.format("{head}") + tail = collection.format("{tail}") + output_filename = "{}%{:0>2}d{}{}".format( + head, padding, filename_suffix, tail + ) repre_files = [] + for idx in indexes: + repre_files.append(output_filename % idx) if not is_sequence: input_filename = input_filenames From ce18809fcd4b8a32e430f152b02ff9aa4d742af7 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:20:59 +0200 Subject: [PATCH 6/8] store full input paths using input_filenames --- openpype/plugins/publish/extract_burnin.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openpype/plugins/publish/extract_burnin.py b/openpype/plugins/publish/extract_burnin.py index d926d5aa2a..da3aca66d2 100644 --- a/openpype/plugins/publish/extract_burnin.py +++ b/openpype/plugins/publish/extract_burnin.py @@ -517,8 +517,11 @@ class ExtractBurnin(openpype.api.Extractor): # Prepare full paths to input files and filenames for reprensetation full_input_paths = [] if is_sequence: - for frame_index in range(1, temp_data["duration"] + 1): - full_input_paths.append(full_input_path % frame_index) + for filename in input_filenames: + filepath = os.path.join( + os.path.normpath(stagingdir), filename + ).replace("\\", "/") + full_input_paths.append(filepath) else: full_input_paths.append(full_input_path) From 0c0dbca84583b0113cc1d3ae588742f51b18243e Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:21:17 +0200 Subject: [PATCH 7/8] store first frame number for burnin script --- openpype/plugins/publish/extract_burnin.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openpype/plugins/publish/extract_burnin.py b/openpype/plugins/publish/extract_burnin.py index da3aca66d2..0632e4af82 100644 --- a/openpype/plugins/publish/extract_burnin.py +++ b/openpype/plugins/publish/extract_burnin.py @@ -468,6 +468,9 @@ class ExtractBurnin(openpype.api.Extractor): if len(input_filenames) > 1: is_sequence = True + # Sequence must have defined first frame + # - not used if input is not a sequence + first_frame = None if is_sequence: collections, _ = clique.assemble(input_filenames) if not collections: @@ -486,6 +489,8 @@ class ExtractBurnin(openpype.api.Extractor): for idx in indexes: repre_files.append(output_filename % idx) + first_frame = min(indexes) + if not is_sequence: input_filename = input_filenames if isinstance(input_filename, (tuple, list)): @@ -509,6 +514,8 @@ class ExtractBurnin(openpype.api.Extractor): temp_data["full_input_path"] = full_input_path temp_data["full_output_path"] = full_output_path + temp_data["first_frame"] = first_frame + new_repre["files"] = repre_files self.log.debug("full_input_path: {}".format(full_input_path)) From b7b8214e227620588d9eff1c491569be3f7537e9 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 4 May 2021 19:21:32 +0200 Subject: [PATCH 8/8] pass collected values to burnin script --- openpype/plugins/publish/extract_burnin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/openpype/plugins/publish/extract_burnin.py b/openpype/plugins/publish/extract_burnin.py index 0632e4af82..5148c65dab 100644 --- a/openpype/plugins/publish/extract_burnin.py +++ b/openpype/plugins/publish/extract_burnin.py @@ -248,7 +248,9 @@ class ExtractBurnin(openpype.api.Extractor): "output": temp_data["full_output_path"], "burnin_data": burnin_data, "options": burnin_options, - "values": burnin_values + "values": burnin_values, + "full_input_path": temp_data["full_input_paths"][0], + "first_frame": temp_data["first_frame"] } self.log.debug(