Difference between revisions of "Source"
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The Source object represents a media file. | The Source object represents a media file. | ||
+ | |||
+ | === Construction === | ||
+ | To construct a new Source, use <tt>Source(path, part=-1)</tt> where <tt>part</tt> is the part index if it is a multi-part source. Use <tt>[[MediaFormat]].parts(path)</tt> to query the available parts in the file. | ||
+ | |||
+ | The <tt>path</tt> passed to Source should contain the frame range to use, in the form: <em>/path/to/file.[0001-0999].ext</em>. Use <tt>[[#SequenceBuilder|SequenceBuilder]]</tt> to aid in building the path in the proper format. | ||
=== Attributes === | === Attributes === | ||
Line 29: | Line 34: | ||
|video | |video | ||
|True if the source has video | |True if the source has video | ||
+ | |- | ||
+ | |channelMask | ||
+ | |the available channels | ||
+ | |6.0 | ||
|- | |- | ||
|part | |part | ||
Line 58: | Line 67: | ||
|} | |} | ||
− | === | + | === SequenceBuilder === |
<tt>tools.sequenceBuilder</tt> contains the <tt>SequenceBuilder</tt> class which can be used to parse a filename and generate details such as start and end frames. <tt>path</tt> should be a frame from a numbered sequence and <tt>SequenceBuilder</tt> will find the start and end frames and construct a resulting path with the frame range built-in, suitable for constructing Sources from, in the form: <b>/path/to/file.[start-end].ext</b>. | <tt>tools.sequenceBuilder</tt> contains the <tt>SequenceBuilder</tt> class which can be used to parse a filename and generate details such as start and end frames. <tt>path</tt> should be a frame from a numbered sequence and <tt>SequenceBuilder</tt> will find the start and end frames and construct a resulting path with the frame range built-in, suitable for constructing Sources from, in the form: <b>/path/to/file.[start-end].ext</b>. | ||
Line 79: | Line 88: | ||
This prints out <b>/images/sequence.[0001-0999].exr</b>. | This prints out <b>/images/sequence.[0001-0999].exr</b>. | ||
+ | |||
+ | === Creating Multi-Layer Sources === | ||
+ | EXR files can contain multiple Layers. There can only be one Source per layer, so if multiple layers must be accessed, the Source must be imported multiple times, and the layer specified using the <tt>layer</tt> property. Here is a code snippet that, given a selected Source with multiple layers, will create the additional Layer Sources automatically. | ||
+ | |||
+ | <source lang="python" enclose> | ||
+ | from fx import * | ||
+ | |||
+ | beginUndo("Create Source Layers") | ||
+ | |||
+ | project = activeProject() | ||
+ | try: | ||
+ | source = selection()[0] | ||
+ | for layer in source.layers: | ||
+ | if layer != "default": | ||
+ | print "Creating Layer: " + layer | ||
+ | path = source.property("path").value | ||
+ | s = Source(path) | ||
+ | project.addItem(s) | ||
+ | s.property("layer").value = layer | ||
+ | except Exception as e: | ||
+ | print e | ||
+ | |||
+ | endUndo() | ||
+ | </source> | ||
=== Adding Sources === | === Adding Sources === | ||
Sources can be added to the Project with the <tt>Project.addItem()</tt> method. | Sources can be added to the Project with the <tt>Project.addItem()</tt> method. |
Latest revision as of 14:36, 5 October 2018
The Source object represents a media file.
Contents
Construction
To construct a new Source, use Source(path, part=-1) where part is the part index if it is a multi-part source. Use MediaFormat.parts(path) to query the available parts in the file.
The path passed to Source should contain the frame range to use, in the form: /path/to/file.[0001-0999].ext. Use SequenceBuilder to aid in building the path in the proper format.
Attributes
Attributes are read-only except where noted.
Name | Description | Added |
---|---|---|
audio | True if the source has audio | |
defaultStream | the default stream | |
fieldDominance | the field dominance setting | |
fieldHandling | the field handling setting | |
key | the source's image cache key | |
streamMask | the streams the source produces | |
video | True if the source has video | |
channelMask | the available channels | 6.0 |
part | The part number | 6.0 |
dependencies | List of dependent sources | 7.0 |
layers | Source layer list | 7.0 |
Methods
Name | Description | |
---|---|---|
path(frame) | generate the path to the desired frame of media | |
metadata(frame) | return a metadata dictionary for the specified frame | 6.0 |
SequenceBuilder
tools.sequenceBuilder contains the SequenceBuilder class which can be used to parse a filename and generate details such as start and end frames. path should be a frame from a numbered sequence and SequenceBuilder will find the start and end frames and construct a resulting path with the frame range built-in, suitable for constructing Sources from, in the form: /path/to/file.[start-end].ext.
from tools.sequenceBuilder import SequenceBuilder
# the image sequence has frames 1-999
path = "/images/sequence.0001.exr"
builder = SequenceBuilder(path)
for f in range(0, builder.frames):
print builder.build(f)
# construct Sources using self.path, which has the frame range included
source = Source(builder.path)
print builder.path
This prints out /images/sequence.[0001-0999].exr.
Creating Multi-Layer Sources
EXR files can contain multiple Layers. There can only be one Source per layer, so if multiple layers must be accessed, the Source must be imported multiple times, and the layer specified using the layer property. Here is a code snippet that, given a selected Source with multiple layers, will create the additional Layer Sources automatically.
from fx import *
beginUndo("Create Source Layers")
project = activeProject()
try:
source = selection()[0]
for layer in source.layers:
if layer != "default":
print "Creating Layer: " + layer
path = source.property("path").value
s = Source(path)
project.addItem(s)
s.property("layer").value = layer
except Exception as e:
print e
endUndo()
Adding Sources
Sources can be added to the Project with the Project.addItem() method.