Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1467 from pypeclub/feature/extract_burnins_with_s…
Browse files Browse the repository at this point in the history
…equences
  • Loading branch information
mkolar authored May 4, 2021
2 parents b0a7209 + b7b8214 commit 7d40636
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 32 deletions.
74 changes: 47 additions & 27 deletions openpype/plugins/publish/extract_burnin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import copy
import tempfile
import clique

import openpype
import openpype.api
Expand Down Expand Up @@ -269,7 +270,9 @@ def main_process(self, instance):
"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(
Expand Down Expand Up @@ -483,32 +486,47 @@ def input_output_paths(self, new_repre, temp_data, filename_suffix):
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

# Sequence must have defined first frame
# - not used if input is not a sequence
first_frame = None
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)
collections, _ = clique.assemble(input_filenames)
if not collections:
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 is_sequence:
# NOTE modified to keep name when multiple dots are in name
basename_parts = basename.split(".")
frame_part = basename_parts.pop(-1)
first_frame = min(indexes)

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(
Expand All @@ -520,24 +538,26 @@ def input_output_paths(self, new_repre, temp_data, filename_suffix):

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))
self.log.debug("full_output_path: {}".format(full_output_path))

# 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)
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)
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.
Expand Down
29 changes: 24 additions & 5 deletions openpype/scripts/otio_burnin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


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 = (
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -289,7 +297,12 @@ def command(self, output=None, args=None, overwrite=False):
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 '',
Expand Down Expand Up @@ -370,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.
Expand Down Expand Up @@ -427,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")
Expand Down Expand Up @@ -591,6 +608,8 @@ def burnins_from_data(
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")

0 comments on commit 7d40636

Please sign in to comment.