12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147 | class ExtractRender(pyblish.api.InstancePlugin):
"""Produce a flattened image file from instance.
This plug-in only takes into account the nodes connected to the composite.
"""
label = "Extract Render"
order = pyblish.api.ExtractorOrder
hosts = ["harmony"]
families = ["render.local"]
def process(self, instance):
# Collect scene data.
application_path = instance.context.data.get("applicationPath")
scene_path = instance.context.data.get("scenePath")
frame_rate = instance.context.data.get("frameRate")
# real value from timeline
frame_start = instance.context.data.get("frameStartHandle")
frame_end = instance.context.data.get("frameEndHandle")
audio_path = instance.context.data.get("audioPath")
if audio_path and os.path.exists(audio_path):
self.log.info(f"Using audio from {audio_path}")
instance.data["audio"] = [{"filename": audio_path}]
instance.data["fps"] = frame_rate
# Set output path to temp folder.
path = tempfile.mkdtemp()
sig = harmony.signature()
func = """function %s(args)
{
node.setTextAttr(args[0], "DRAWING_NAME", 1, args[1]);
}
%s
""" % (sig, sig)
harmony.send(
{
"function": func,
"args": [instance.data["setMembers"][0],
path + "/" + instance.data["name"]]
}
)
harmony.save_scene()
# Execute rendering. Ignoring error cause Harmony returns error code
# always.
args = [application_path, "-batch",
"-frames", str(frame_start), str(frame_end),
scene_path]
self.log.info(f"running: {' '.join(args)}")
proc = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stdin=subprocess.PIPE
)
output, error = proc.communicate()
self.log.info("Click on the line below to see more details.")
self.log.info(output.decode("utf-8"))
# Collect rendered files.
self.log.debug(f"collecting from: {path}")
files = os.listdir(path)
assert files, (
"No rendered files found, render failed."
)
self.log.debug(f"files there: {files}")
collections, remainder = clique.assemble(files, minimum_items=1)
assert not remainder, (
"There should not be a remainder for {0}: {1}".format(
instance.data["setMembers"][0], remainder
)
)
self.log.debug(collections)
if len(collections) > 1:
for col in collections:
if len(list(col)) > 1:
collection = col
else:
collection = collections[0]
# Generate thumbnail.
thumbnail_path = os.path.join(path, "thumbnail.png")
args = ayon_core.lib.get_ffmpeg_tool_args(
"ffmpeg",
"-y",
"-i", os.path.join(path, list(collections[0])[0]),
"-vf", "scale=300:-1",
"-vframes", "1",
thumbnail_path
)
process = subprocess.Popen(
args,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
stdin=subprocess.PIPE
)
output = process.communicate()[0]
if process.returncode != 0:
raise ValueError(output.decode("utf-8", errors="backslashreplace"))
self.log.debug(output.decode("utf-8", errors="backslashreplace"))
# Generate representations.
extension = collection.tail[1:]
representation = {
"name": extension,
"ext": extension,
"files": list(collection),
"stagingDir": path,
"tags": ["review"],
"fps": frame_rate
}
thumbnail = {
"name": "thumbnail",
"ext": "png",
"files": os.path.basename(thumbnail_path),
"stagingDir": path,
"tags": ["thumbnail"]
}
instance.data["representations"] = [representation, thumbnail]
if audio_path and os.path.exists(audio_path):
instance.data["audio"] = [{"filename": audio_path}]
# Required for extract_review plugin (L222 onwards).
instance.data["frameStart"] = frame_start
instance.data["frameEnd"] = frame_end
instance.data["fps"] = frame_rate
self.log.info(f"Extracted {instance} to {path}")
|