Mocha Pro Python Guide
Mocha Pro Python Guide
0 Python
Scripting Guide
Table of Contents
Introduction ................................................................................................................ 2
Installation ................................................................................................................. 2
Running mocha Python ............................................................................................. 3
Python Script Editor .................................................................................................. 3
The Editor Window ............................................................................................ 3
The Output Window ........................................................................................... 3
The Main mocha Python Structure ........................................................................... 4
Top level mocha methods ................................................................................. 4
The mocha.project Module ................................................................................ 4
The mocha.exporters Module ............................................................................ 5
The mocha.tools Module .................................................................................... 6
The mocha.mediaio Module ............................................................................... 6
The mocha.ui Module ........................................................................................ 7
Qt Script Requirements ............................................................................................. 7
QCoreApplication ............................................................................................... 7
Creating a New Project ............................................................................................. 7
Modifying project properties ............................................................................... 8
Creating a Stereo Project .................................................................................. 9
Layers and Groups ................................................................................................. 10
Shape Contours ............................................................................................... 12
Obtaining the Current Clip ............................................................................... 15
Rendering ................................................................................................................ 16
Rendering Removes, Inserts and Stabilization ................................................ 16
Rendering Matte Shapes ................................................................................. 18
Watching Renders ............................................................................................ 19
The Parameter API ................................................................................................. 20
Controlling and Catching UI actions ....................................................................... 21
Using init.py and Initialization Functions ................................................................. 22
The init.py path ................................................................................................ 22
Using init.py ..................................................................................................... 23
Creating Interfaces .................................................................................................. 24
1
mocha® v5.2.0 Python
Scripting Guide
Introduction
Welcome to the mocha Pro v5.2.0 Python scripting guide.
This User Guide will take you through some of the python functions for mocha Pro
v5.2.0. Additionally you can check the mocha Python reference available online.
The guide assumes you already have a basic understanding of Python coding. For
guides on how to learn Python, please refer to https://python.org.
Installation
Python for mocha installs with the Linux and OS X packages by default. On Windows,
Python installs as a separate bundle in the mocha Pro installer. When installing, you
need to make sure to select all features - not just the top level feature.
The mocha Python command tools are available per system in the
following default locations:
• OS X: /Applications/mocha Pro.app/Contents/MacOS/python
• Linux: /opt/isl/mochaV5/python/bin/python
The mocha package uses Python version 2.7.6. For version use and compatibility
please read the standard Python 2.7.6 documentation: https://docs.python.org/2/
2
mocha® v5.2.0 Python
Scripting Guide
You can also install the mocha module directly to your own Python installation.
Now when you run your version of Python you should be able to import the mocha
module.
The script editor is intentionally barebones and is not meant to replace a fully featured
IDE, but will color your syntax for easier readability.
3
mocha® v5.2.0 Python
Scripting Guide
These are especially useful for when you are running external scripts.
mocha.project
• Global functions: For getting project-level information such as the current
project
4
mocha® v5.2.0 Python
Scripting Guide
• Project: Main project class. Provides methods and properties for general project
management of layers, groups, rendering and output directories
5
mocha® v5.2.0 Python
Scripting Guide
mocha.exporters
• AbstractCameraSolveExporter: Abstract camera solve exporter class.
Inherit the class to create your own exporter formats. Inherited by
CameraSolveExporter.
• AbstractShapeDataExporter: Abstract class for the Shape Data exporter.
Inherit the class to create your own custom formats. Inherited by
ShapeDataExporter.
• AbstractTrackingDataExporter: Abstract tracking data exporter class.
Inherit the class to create your own exporter formats. Inherited by
TrackingDataExporter.
• CameraSolveExporter: Camera data exporter class. Wraps a predefined/
custom mocha exporter inside.
• ShapeDataExporter: Class for defining the shape data to export
• ShapeExportData: Shape data exporter class. Wraps a predefined/custom
mocha exporter inside.
• TrackingDataExporter: Tracking data exporter class. Wraps a predefined/
custom mocha exporter inside.
mocha.tools
• Global functions: Functions for registering and setting tool instances.
• AbstractTool: Abstract tool class that provides overridable methods to
determine custom tools. Every overridable method must be implemented.
• InputEvent: Event handling for mouse interaction and contour data.
6
mocha® v5.2.0 Python
Scripting Guide
mocha.mediaio
• AbstractImageIOModule: Abstract image IO class that provides overridable
methods to determine custom image input and output operations. Every
overridable method must be implemented. The methods should not call each
other.
• ImageData: Main class for access to image data fields.
Qt Script Requirements
Some aspects of mocha Python code will require the creation of Qt Objects to handle
certain functionality.
QCoreApplication
A QCoreApplication object must always be created before creating a Project object.
If you don’t create the QCoreApplication Object, then the internal parameter
notification system does not work and you may get unexpected results or errors when
dealing with parameter changes.
app = QCoreApplication(sys.argv)
To do this, you first need to import the Clip and Project classes from mocha.project:
7
mocha® v5.2.0 Python
Scripting Guide
app = QCoreApplication(sys.argv)
You then create a new Clip object and assign it to a new Project object:
At this point the project is now in memory. You can delete the original Clip object as
the project contains a deep copy - the original clip is not part of the project.
To save the project, use the save_as() function and define a mocha project file and
path.
proj.save_as('/path/to/filename.mocha')
At any point if you want to save the project again, you can use:
proj.save()
This will save to the project file you defined with save_as().
8
mocha® v5.2.0 Python
Scripting Guide
proj.notes = 'New Project'
• View(0): Left
• View(1): Right
proj.default_hero_view = 0
To add new streams to existing clips so you can map them to views, use the
add_stream method.
9
mocha® v5.2.0 Python
Scripting Guide
myClip.assign_project_view(View(0), View(1))
myClip.delete_stream(View(1))
Listing layers
10
mocha® v5.2.0 Python
Scripting Guide
print layer_list[0].name
Tracking layers
#Track any layer in the project that has a process cog turned on
proj.track_layers()
#Track layers in the project for a specific frame range (all parameters
are optional)
proj.track_layers(start_index=5, stop_index=45)
#Track backwards by having a high start index and a low stop index
proj.track_layers(start_index=100, stop_index=1)
To create a new layer, you must assign it to a particular input clip, just as though you
were drawing a layer on a clip inside mocha. You can define 4 main properties when
creating a layer:
11
mocha® v5.2.0 Python
Scripting Guide
You only need to assign the first property (the input clip you want to assign to the layer)
Creating a layer
At this point the layer is empty, so you need to add a shape contour. This is where it
starts to get interesting!
Shape Contours
Adding contours to a layer involves setting up the content to draw the layer. You can
add a contour to a layer, but first it needs point data. Each point in a contour has a
number of important parameters that need to be set.
12
mocha® v5.2.0 Python
Scripting Guide
bezier_point = BezierControlPointData(corner=False,
active=True,
x=600.0, y=500.0,
edge_width=0.0,
edge_angle_ratio=0.0,
curve_angle=0.0,
handle_offset_backward=None,
handle_offset_forward=None)
Of course, one point is not enough for a shape, so you need to set
a tuple of BezierControlPointData objects to define a final contour, using
add_bezier_Contour(). This takes two arguments, the frame you want to start on,
and a tuple of point data.
13
mocha® v5.2.0 Python
Scripting Guide
xspline_point = XControlPointData(corner=False,
active=True,
x=600.0,
y=500.0,
edge_width=0.0,
edge_angle_ratio=0.5,
weight=0.25)
Of course, one point is not enough for a shape, so you need to set a tuple of
XControlPointData objects to define a final contour, using add_xpline_Contour().
This takes two arguments, the frame you want to start on, and a tuple of point data.
Inserting Points
You can also insert points into existing shapes using the insert_point()
function. To do this you just create point data as normal above. You need
14
mocha® v5.2.0 Python
Scripting Guide
layer_contour = proj.layers[0].contours[0]
x_point = XControlPointData(corner=False,
active=True,
x=400.0,
y=300.0,
edge_width=0.0,
edge_angle_ratio=0.5,
weight=0.25)
end_idx = len(layer_contour.control_points)
layer_contour.insert_point(0.0, x_point, end_idx)
You can also set these clips using the appropriate setter:
15
mocha® v5.2.0 Python
Scripting Guide
from mocha.ui import set_displayed_clip
default_clip = get_current_project().default_trackable_clip
Rendering
Rendering Removes, Inserts and Stabilization
In addition to creating shapes, we can also render from each module. In the examples
below we show Remove, but the same operations are available for Insert and Stabilize.
• RenderInsertOperation
• RenderRemoveOperation
• RenderStabilizeOperation
To handle removes and exports, you need to have the following mocha classes loaded:
1. Defining a RenderRemoveOperation()
2. Calling the render() function
3. Exporting the remove with the export() function
16
mocha® v5.2.0 Python
Scripting Guide
• revert_to_clip (Clip): The clip to revert to if a rendered frame does not exist
• directory (str): The output clip directory.
• extension (str): The file extension (.TIF, .DPX,etc.)
• prefix (str): Any prefix you want at the start of the file name
• suffix (str): Any suffix you want at the end of the file name
• index_start (int): The start frame to export
• index_stop (int): The end frame to export
• index_width (int): The index width of your rendered frames
• views (list of View instances): Views to export.
#Assign a project
proj = Project('/path/to/project.mocha')
#Assign a clip
clip = proj.clips['source_clip']
#define the layer you want to use in the project for the remove
layer = proj.find_layers('REMOVE LAYER')[0]
17
mocha® v5.2.0 Python
Scripting Guide
('index_width', 0)))
To handle shape exports, you require the following mocha classes loaded:
clip = proj.clips['source_clip']
layer = proj.find_layers('Layer 1')[0]
new_clip = proj.export_rendered_shapes([layer],
clip,
ColorizeOutput.Grayscale,
render_output_dir,
'.png',
18
mocha® v5.2.0 Python
Scripting Guide
'Matte',
'',
1,
3,
0)
Watching Renders
You can also create watchers for the rendering so that you can trigger events or just
keep an eye on progress.
The watcher example below connects to a render process and outputs the render and
export progress to the command line.
app = QCoreApplication(sys.argv)
proj = Project('/_clips/Results/Fish_remove.mocha')
rm = RenderRemoveOperation()
layer = proj.find_layers('REMOVE FISHY')[0]
def on_start_rendering():
sys.stdout.write('Rendering started.\nProgress:\n')
sys.stdout.write('[ %s ]' % (' ' * 100,))
def on_start_exporting():
print 'Exporting started'
def on_progress(progress):
sys.stdout.write('\r')
sys.stdout.write('[ %s%s ]' % ('#' * progress, ' ' * (100 -
progress)))
def on_message(message):
print message
19
mocha® v5.2.0 Python
Scripting Guide
def on_finish():
print '\n'
print 'Rendering is finished'
print 'Exporting!'
Example of using the parameter API to get the surface X/Y coordinates of Layer_1
app = QApplication.instance()
proj = get_current_project()
name = 'Layer_1'
20
mocha® v5.2.0 Python
Scripting Guide
scorners = []
print scorners
The parameter system opens up a large range of options for users wishing to write
tools to modify or create layers with different properties.
In the example code above, once we have the layer’s surface coordinates we can then
use those positions for various tasks, such as drawing splines that fit the surface, or
adjust another layer’s surface to match the current one.
menu_file = get_menus()['MenuFile']
save_action_handler = ActionTriggerHandler(saveAction)
def my_handler(save_func):
reply = QMessageBox.question(None, 'Message',
21
mocha® v5.2.0 Python
Scripting Guide
'Are you sure to save the project?',
QMessageBox.Yes | QMessageBox.No,
QMessageBox.No)
if reply == QMessageBox.No:
return
save_func()
file=get_current_project().project_file)
time.sleep(1)
print 'Done'
save_action_handler.handler = my_handler
This can be as simple as actions you want to perform when you start mocha, but the
real power comes from being able to set up tools in the interface using widgets.
You can also set the environment variable MOCHA_INIT_SCRIPT to control where the
path of the init.py initialization script resides.
If the MOCHA_INIT_SCRIPT environment variable points to a file, that file will be used,
if it points to a directory, it will look specifically for init.py in that directory. If unset, the
default locations above will be used.
22
mocha® v5.2.0 Python
Scripting Guide
Using init.py
Below we show a detailed example of using init.py for creating a user-entry tool to
prepend a word onto the front of all selected layers.
We also list code at the end to show how to add this to the file menu in mocha and
load a dialog for user entry.
Some knowledge of PySide and Qt is helpful here, but if you follow along the script you
can see how the widgets are created.
class LayerPrepend():
def __init__(self):
self.app = QApplication.instance()
self.layer_tree = self.get_layer_tree()
self.layer_prepend()
def get_layer_tree(self):
widgets = get_widgets()
return widgets['LayerControl']
def layer_prepend(self):
selected_layers = self.layer_tree.selectedIndexes()
if len(selected_layers) > 0:
dlg = QDialog()
layout = QFormLayout()
edt = QLineEdit()
layout.addRow("Prefix", edt)
btn_box = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel)
btn_box.accepted.connect(dlg.accept)
btn_box.rejected.connect(dlg.reject)
23
mocha® v5.2.0 Python
Scripting Guide
layout.addRow(btn_box)
dlg.setLayout(layout)
if dlg.exec_() == QDialog.Accepted:
self.prepend_selected_layers(edt.text())
self.layer_tree.update()
project = get_current_project()
selected_layers = self.layer_tree.selectedIndexes()
for idx in selected_layers:
layer = project.layer(idx.row())
layer.name = prefix + layer.name
If you need to check Python error output after loading an init.py script, load the error
log from the Help menu, or load mocha via the terminal.
Creating Interfaces
You can create GUI inside mocha using the PySide Qt API. Showing a widget and
connecting it to an action or function is very simple:
combo = QComboBox()
24
mocha® v5.2.0 Python
Scripting Guide
combo.addItems(['Layer 1', 'Layer 2'])
def nameSelected(name):
print name
combo.activated[str].connect(nameSelected)
combo.show()
You can also create menu items, by locating the menu bar:
Creating Tools
When you want to extend mocha functionality further by using interactive tools, you
need to import the mocha.tools API. These set of classes allow you to read mouse
events and position, along with registering the necessary tool icon or action in the
interface.
When defining your tool class, it needs to inherit the AbstractTool class from
mocha.tools to initialize correctly.
class PointHunt(AbstractTool):
25
mocha® v5.2.0 Python
Scripting Guide
def __init__(self, project):
action = QAction(None)
action.setText('Point Hunter Tool')
action.setIcon(QIcon('/myicons/pointhunt.png'))
AbstractTool.__init__(self, action)
action.setParent(self)
tools_bar = find_widget('ToolsBar', QToolBar)
tools_bar.addAction(action)
Adding an icon using the setIcon function command from PySide.QtGui will still define
the icon on the the toolbar if your icon file path does not exist.
Once the init class is defined, you can then monitor interaction with the tool using
activation and mouse event functions.
def on_activate(self):
print 'TOOL ACTIVATED'
def on_deactivate(self):
print 'TOOL DEACTIVATED'
The on_activate function is useful for initializing items you only want to occur when
the tool has been launched from the toolbar or menu item. A good example of this is
to grab the current project on when the tool has become active.
on_activate example
def on_activate(self):
self.proj = get_current_project()
The on_deactivate function is useful for running items you only want to occur when
switching away from the tool by either selecting a different tool or another action.
26
mocha® v5.2.0 Python
Scripting Guide
on_deactivate example
def on_deactivate(self):
release_bees()
In the code below we have made a tool that creates a simple 4-point spline to quickly
place in a shot for spot removal.
for x, y in points:
x_point = XControlPointData(corner=False,
active=True,
x=float(x) + pos.x(),
27
mocha® v5.2.0 Python
Scripting Guide
y=float(y) + pos.y(),
edge_width=0.0,
edge_angle_ratio=0.5,
weight=0.25)
x_point_data.append(x_point)
x_contour = new_layer.add_xspline_contour(0.0,
tuple(x_point_data))
return x_contour
def on_activate(self):
self.proj = get_current_project()
register_custom_tool_type(SpotCleaner)
Custom Exporters
With the ability to dive into most aspects of the project file, it is a lot easier to now write
your own tracking, shape and camera solve exporters for your own applications.
To make this more intuitive, we have exporter classes which can register a new export
type as part of the standard exporters. In fact two of our new shape exporters, Fusion
and Silhouette, have been written entirely in Python.
You’re also going to need the QByteArray class from PySide.QtCore to create the
final data output.
28
mocha® v5.2.0 Python
Scripting Guide
As a basic example, let’s set up an exporter that will write the x,y coordinates of the
surface per frame to a CSV file. First, you need to create a new exporter class that
inherits from the AbstractTrackingDataExporter class. Here we initialize a super
class and load the name of the exporter.
class CSVExporter(AbstractTrackingDataExporter):
'''
Implementation of the CSV Track exporter.
'''
def __init__(self):
super(CSVExporter, self).__init__('CSV File (*.csv)', '')
There are additional parameters you can set to initialize the class:
• name (unicode): Name of the exporter which will be displayed in the Export Tracking
Data dialog drop-down list. It Should contain a file mask in brackets e.g. Foo (*.bar)
• extension: Additional extension.
• number_of_data_streams: The number of result files required. If it equals to 1
(the default) then the Copy to Clipboard button will be enabled in the GUI.
• remove_lens_distortion: Whether the exporter supports removing of a lens
distortion.
• export_multiple_views: Whether the exporter supports multiple views.
• export_interlaced: Whether the exporter supports interlaced footage.
In the example above, we’re keeping it simple, so we are leaving the defaults and only
setting the export name and file extension.
The brunt of the work is handled in the do_export function for the class. This function
returns the final data that will go to file or the clipboard.
29
mocha® v5.2.0 Python
Scripting Guide
class CSVExporter(AbstractTrackingDataExporter):
'''
Implementation of the CSV Track exporter.
'''
def __init__(self):
super(CSVExporter, self).__init__('CSV File (*.csv)', '') #Define
the CSV exporter
self._project = None
def error_string(self):
return ''
#Get the corner points of the surface for a given time and layer
def get_surface_parameters(self, layer, time, view):
surface_corners = []
for idx in range(0, 4):
surface_corners.extend(layer.get_surface_position(idx, time,
view))
return surface_corners
30
mocha® v5.2.0 Python
Scripting Guide
3. tracking_file_path (unicode): The absolute file path to save which has been chosen
by a user in a file dialog.
4. time (PySide.QtCore.double):The frame index.
5. view (mocha.project.View): The selected view to export.
6. options: A dictionary with keys of type QString and values of type bool. The 3
options for this are Invert, Stabilize and RemoveLensDistortion, which relate to the
3 checkboxes available in the export dialog.
Note that all of the do_export parameters will automatically be passed by the interface
unless you specifically override them.
To do this, you can grab the existing export output and modify it as you require, then
assign it to a new exporter.
class NukeRotoPaintExtra(AbstractShapeDataExporter):
def __init__(self):
super(NukeRotoPaintExtra, self).__init__("Nuke RotoPaint [Basic]
Extra (*.nk)", "", number_of_data_streams=1,
export_multiple_shapes=True,
export_open_splines=True,
export_multiple_views=True,
export_interlaced=True)
self.nuke_exporter =
AbstractShapeDataExporter.registered_exporters()['Nuke RotoPaint [Basic]
(*.nk)']
31
mocha® v5.2.0 Python
Scripting Guide
def error_string(self):
return ""
nuke_exporter = NukeRotoPaintExtra()
nuke_exporter.register()
This makes it much easier to set up profiles for different users, or define settings based
on particular conditions.
For a full list of available setting parameters, see the mocha Python reference.
import mocha
32
mocha® v5.2.0 Python
Scripting Guide
:return: difference dict {key: (value1, value2)}
:rtype: dict
"""
diff = {}
assert settings1.group() == settings2.group()
child_keys = set(settings1.childKeys())
child_keys.update(settings2.childKeys())
for key in child_keys:
value1 = settings1.value(key)
value2 = settings2.value(key)
if value1 != value2:
diff_key_name = "{0}/{1}".format(settings1.group(), key)
diff[diff_key_name] = (value1, value2)
child_groups = set(settings1.childGroups())
child_groups.update(settings2.childGroups())
for group in child_groups:
settings1.beginGroup(group)
settings2.beginGroup(group)
diff.update(settings_diff(settings1, settings2))
settings2.endGroup()
settings1.endGroup()
return diff
# Overridden settings
overridden_settings = mocha.Settings(override=True, read_overridden=True)
# Test that overloads have been not set yet, so the settings must be
identical
assert not(settings_diff(real_settings, overridden_settings))
assert not(settings_diff(real_settings, checking_settings))
assert not(settings_diff(overridden_settings, checking_settings))
#Toggle an override of the Full Screen setting and test it against the
saved setting
full_screen = overridden_settings.value('FullScreen')
33
mocha® v5.2.0 Python
Scripting Guide
overridden_settings.setValue('FullScreen', not full_screen)
assert not(settings_diff(overridden_settings, checking_settings))
diff = settings_diff(overridden_settings, real_settings)
assert '/FullScreen' in diff
overridden_settings.setValue('FullScreen', full_screen)
'/opt/isl/mochaproV5/python' '/opt/isl/mochaproV5/python/mocharender.py'
Below are the various options to render. After you have typed in your options and
pressed Enter, mocha will apply the render to layers with cogs turned on in the saved
project file.
In each case you can choose either the abbreviated option (such as -p
PROJECT_PATH), or the more descriptive option (--project=PROJECT_PATH):
-p PROJECT_PATH, --project=PROJECT_PATH
34
mocha® v5.2.0 Python
Scripting Guide
-g LAYER_NAMES_IN_GROUPS, --group=LAYER_NAMES_IN_GROUPS
Group of layers to render. Specify layer names after the group name to render them
only. Duplicated layers will be ignored.
-r RELINK_PATH, --relink-path=RELINK_PATH
Path to the first clip file for relinking. This option is useful if you have sent your project
file to a different machine to render and you need to relink the source footage without
opening the GUI.
-L MIN_INDEX, --lower-index=MIN_INDEX
Lower clip frame index for relinking. If you are only using a certain frame range for the
original clip.
-U MAX_INDEX, --upper-index=MAX_INDEX
Upper clip frame index for relinking. If you are only using a certain frame range for the
original clip.
-c CLIP_NAME, --clip-name=CLIP_NAME
Clip name, i.e. the name of the source clip you are using to render with.
-V VIEW_INDEX, --view=VIEW_INDEX
Clip view index. By default this is zero(0), but if you are using a multi-view clip you can
set the index here. By default Left and Right views are 0 and 1 respectively.
-D OUTPUT_DIR, --output-directory=OUTPUT_DIR
Path to the output directory for the rendered export.
-E OUTPUT_EXT, --output-extension=OUTPUT_EXT
Output clip extension. This is where you define your format, such as TIF, DPX, EXR etc.
-P OUTPUT_PREFIX, --prefix=OUTPUT_PREFIX
Output clip prefix. Such as Remove_
-S OUTPUT_SUFFIX, --suffix=OUTPUT_SUFFIX
Output clip file name suffix if you require one.
-I FRAME_IN, --frame-in=FRAME_IN
Start frame index. The in point for your render.
-O FRAME_OUT, --frame-out=FRAME_OUT
35
mocha® v5.2.0 Python
Scripting Guide
-R RENDER_TYPE, --render-type=RENDER_TYPE
Rendering operation type (remove, insert, stabilize). Note the US spelling of stabilize!
-v LOG_LEVEL, --verbosity=LOG_LEVEL
Show the render/export operation progress. -v1 is minimum, -v4 is maximum.
• --fbo=FBO*
Use offscreen buffers. Use 1 to use frame buffers, 0 to turn them off. If not set,
mocha will use the setting in Preferences.
• --offset
First file number of the exporting image sequence. If specified with no arguments,
the project offset is used.
The following command performs removing contents of Layer 2 and saves entire result
clip to the /tmp/rendered directory.
Command
Output
36
mocha® v5.2.0 Python
Scripting Guide
[INFO] 2015-11-05 14:26:17,471 Exporting complete
[INFO] 2015-11-05 14:26:17,472 Exported clip has been written to /tmp/
rendered
'/opt/isl/mochaproV5/python' '/opt/isl/mochaproV5/python/
mochaexport.py' [options]
The mochaexport.py script can export layer data to different export formats. There are
4 types of export (see --export-type option):
1. shapes: Refers to options in the "Track tab → Export Shape Data…" dialog inside
the mocha GUI.
2. tracking: Refers to options in the "Track tab → Export Tracking Data…" dialog
inside the mocha GUI.
4. rendered-shapes: Renders layer shapes to file. This is a bit different from other
exports. You don’t specify --export-type, --exporter-name and --file-path options for
rendered shapes. Required options are --output-directory --output-extension, list of
layer names.
Optional inputs are --frame-in, --frame-out, --prefix, --suffix, --index-width.
37
mocha® v5.2.0 Python
Scripting Guide
Below are the various options to export. In each case you can choose either the
abbreviated option (such as -p PROJECT_PATH), or the more descriptive option (--
project=PROJECT_PATH):
-p PROJECT_PATH, --project=PROJECT_PATH
Path to the mocha project. E.g. /projects/mochaprojects/Results/myproject.mocha
-g LAYER_NAMES_IN_GROUPS, --group=LAYER_NAMES_IN_GROUPS
Group of layers to export. Specify layer names after the group name to export them
only. Duplicated layers will be ignored.
-e EXPORT_TYPE, --export-type=EXPORT_TYPE
The Export type. The choices are rendered-shapes, shapes, tracking, or camera-solve.
-D OUTPUT_DIR, --output-directory=OUTPUT_DIR
Path to the output directory.
-E OUTPUT_EXT, --output-extension=OUTPUT_EXT
Output clip extension. If this option is not set, it will default to a PNG file when exporting
rendered shapes.
-P OUTPUT_PREFIX, --prefix=OUTPUT_PREFIX
Output clip prefix. For use if you are exporting rendered shapes. Default is no prefix.
-S OUTPUT_SUFFIX, --suffix=OUTPUT_SUFFIX
Output clip suffix. For use if you are exporting rendered shapes. Default is no suffix.
-V VIEWS, --views=VIEWS
Names or abbreviations of views to export.
-v LOG_LEVEL, --verbosity=LOG_LEVEL
Show the export operation progress
-n EXPORTER_NAME, --exporter-name=EXPORTER_NAME
A name of an exporter. Can accept Regular Expressions as /regexp/. This is required
if you are exporting shapes, tracking or camera solves.
-f FILE_NAME, --file-path=FILE_NAME
Exporter output file name.
-t TIME, --time=TIME
Frame time.
-C COLORIZE, --colorize=COLORIZE
38
mocha® v5.2.0 Python
Scripting Guide
Colorize output option. This is used to export the colored version of the mattes. Options
are grayscale, matte-color, or layer (for layer id gradient). The default is grayscale.
-I FRAME_IN, --frame-in=FRAME_IN
Start frame index. Default is 0.
-O FRAME_OUT, --frame-out=FRAME_OUT
Stop frame index.
-w INDEX_WIDTH, --index-width=INDEX_WIDTH
Output index width. Default is 0.
-L, --exporters-list
If set, the script will output list of all possible exporters grouped by their types.
-i, --invert
Mimes Invert checkbox of the Export Tracking Data dialog.
-R, --remove-lens-distortion
Mimes Remove lens distortion checkbox of the Export Tracking Data dialog.
-s, --stabilize
If set, stabilize data will be exported. Use it together with a tracking exporter type.
• --fbo=FBO*
Use offscreen buffers. Use 1 to use frame buffers, 0 to turn them off. If not set,
mocha will use the setting in Preferences.
• --offset
First file number of the exporting image sequence. If specified with no arguments,
the project offset is used.
Command
Output:
39
mocha® v5.2.0 Python
Scripting Guide
Command
Output:
Using processEvents()
Further Reference
For complete reference of the mocha Python API, see here: http://
www.imagineersystems.com/support/documentation/python/
40