-
Notifications
You must be signed in to change notification settings - Fork 1
/
extract_quicktime.py
112 lines (89 loc) · 3.68 KB
/
extract_quicktime.py
1
2
3
4
5
6
7
8
9
10
11
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
import os
import contextlib
import pyblish.api
import pyblish_magenta.plugin
from pyblish_magenta.vendor import capture
from maya import cmds
@pyblish.api.log
class ExtractQuicktime(pyblish_magenta.api.Extractor):
"""Extract review instances as a quicktime
Arguments:
startFrame (float): Start frame of output
endFrame (float): End frame of output
width (int): Width of output in pixels
height (int): Height of output in pixels
format (str): Which format to use for the given filename,
defaults to "qt"
compression (str): Which compression to use with the given
format, defaults to "h264"
offScreen (bool): Capture off-screen
maintainAspectRatio (bool): Whether or not to modify height for width
in order to preserve the current aspect ratio.
show (str): Space-separated list of which node-types to show,
e.g. "nurbsCurves polymeshes"
"""
families = ["review"]
hosts = ["maya"]
optional = True
label = "Quicktime"
def process(self, instance):
self.log.info("Extracting capture..")
camera = instance[0]
current_min_time = cmds.playbackOptions(minTime=True, query=True)
current_max_time = cmds.playbackOptions(maxTime=True, query=True)
default_width = cmds.getAttr("defaultResolution.width")
default_height = cmds.getAttr("defaultResolution.height")
width = instance.data('width') or default_width
height = instance.data('height') or default_height
start_frame = instance.data('startFrame') or current_min_time
end_frame = instance.data('endFrame') or current_max_time
format = instance.data('format') or 'qt'
compression = instance.data('compression') or 'h264'
off_screen = instance.data('offScreen', False)
maintain_aspect_ratio = instance.data('maintainAspectRatio', True)
cam_opts = capture.CameraOptions()
# Set viewport settings
view_opts = capture.ViewportOptions()
view_opts.displayAppearance = "smoothShaded"
if 'show' in instance.data():
for nodetype in instance.data('show').split():
self.log.info("Overriding show: %s" % nodetype)
if hasattr(view_opts, nodetype):
setattr(view_opts, nodetype, True)
else:
self.log.warning("Specified node-type in 'show' not "
"recognised: %s" % nodetype)
else:
view_opts.polymeshes = True
view_opts.nurbsSurfaces = True
# Ensure name of camera is valid
path = self.temp_dir(instance)
if format == 'image':
# Append sub-directory for image-sequence
path = os.path.join(path, camera)
else:
path = os.path.join(path, instance.name + ".mov")
self.log.info("Outputting to %s" % path)
with maintained_time():
output = capture.capture(
camera=camera,
width=width,
height=height,
filename=path,
start_frame=start_frame,
end_frame=end_frame,
format=format,
viewer=False,
compression=compression,
off_screen=off_screen,
maintain_aspect_ratio=maintain_aspect_ratio,
viewport_options=view_opts,
camera_options=cam_opts)
instance.set_data("reviewOutput", output)
@contextlib.contextmanager
def maintained_time():
ct = cmds.currentTime(query=True)
try:
yield
finally:
cmds.currentTime(ct, edit=True)